About NSDictionary

NSDictionary 初始化方法如下:

  • 创建兼初始化(先记住这几种)
+ (instancetype)dictionary;
+ (instancetype)dictionaryWithObject:(ObjectType)object forKey:(KeyType )key;
+ (instancetype)dictionaryWithObjects:(NSArray *)objects 
                              forKeys:(NSArray> *)keys;
  • 例如
self.SelectViewCtrlList = [NSDictionary dictionaryWithObjects:@[@"1",@"2",@"3"]
                                                      forKeys:@[@"MainVC",@"Bluetooth Setting",@"WiFi Setting"]];
  • [[NSDictionary alloc] initWith...]的方法先不记录

NSMutableDictionary 初始化举例

NSMutableDictionary *hexDic = [[NSMutableDictionary alloc] initWithCapacity:3];
[hexDic setObject:@"0" forKey: @"0000"];
[hexDic setObject:@"1" forKey: @"0001"];
[hexDic setObject:@"2" forKey: @"0010"];

你可能感兴趣的:(About NSDictionary)