Objective-C Foundation框架实践——NSMutableDictionary(一)

     字典也可以是可变的。常见的可变字典的方法如下:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
  @autoreleasepool {
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    
    //添加键值对
    [dict setObject:@"a" forKey:@"1"];
    [dict setObject:@"b" forKey:@"2"];
    [dict setObject:@"c" forKey:@"3"];
    
    NSLog(@"%@",dict);
    
    
    
    //删除键值对
    
    //删除所有对象;
//    [dict removeAllObjects];
//    [dict removeObjectForKey:@"2"];


  }
    return 0;
}

Objective-C Foundation框架实践——NSMutableDictionary(一)_第1张图片



github主页:https://github.com/chenyufeng1991  。欢迎大家访问!

你可能感兴趣的:(Objective-C,Foundation)