• NSMutableDictionary


    NSMutableDictionary 用于处理值对集合。保存到键的对象必须实现了copyWithZone:方法。和NSMutableArray一样添加到容器时对象收到retain消息,把对象从容器中移除时收到release消息,任何想在移除对象还要对该对象进行操作必须先对该对象发出一条retain消息,在使用完成后需要release。
    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[])
    {
    
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        //创建Dictionary,Capacity仅控制初始化大小
        NSMutableDictionary *fruits = [NSMutableDictionary dictionaryWithCapacity:2];
        [fruits setObject:@"Orange" forKey:@"OrangeKey"];
        [fruits setObject:@"Apple" forKey:@"AppleKey"];
        [fruits setObject:@"Blueberry" forKey:@"BlueberryKey"];
        NSLog(@"%@", fruits);
        
        //获取一个对象
        id oneObj = [fruits objectForKey:@"AppleKey"];
        NSLog(@"%@", oneObj);
    
        //如果找不到应的条目,返加nil
        id noObj = [fruits objectForKey:@"aaa"];
        NSLog(@"%@", noObj);
        
        [pool drain];
        return 0;
    }
    
  • 相关阅读:
    ValueStack、ActionContext
    s debug
    1923: [Sdoi2010]外星千足虫
    1013: [JSOI2008]球形空间产生器sphere
    HDU 3923 Invoker
    poj 1286 Necklace of Beads
    HDU 3037:Saving Beans
    2440: [中山市选2011]完全平方数
    1101: [POI2007]Zap
    1968: [Ahoi2005]COMMON 约数研究
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/2038548.html
Copyright © 2020-2023  润新知