字典对象NSDictionary

NSDictionary用于描述字典对象,数组的下标是整型数,字典的下标是字符串类型的key

创建:

+(instancetype)dictionary+(instancetype)dictionaryWithObject:(ObjectType)anObjectforKey:(id<NSCopying>)aKey+(instancetype)dictionaryWithObjects:(NSArray<ObjectType>*)objectsforKeys:(NSArray<id<NSCopying>>*)keys+(instancetype)dictionaryWithObjectsAndKeys:(id)firstObject,...

字面值:

NSDictionary*dict=@{@"key1":@"value1",@"key2":@"value2”};//常量方式

基本操作:

@property(readonly)NSUIntegercount-(ObjectType)objectForKey:(KeyType)aKey

文件/URL相关:

+(NSDictionary<KeyType,ObjectType>*)dictionaryWithContentsOfFile:(NSString*)path+(NSDictionary<KeyType,ObjectType>*)dictionaryWithContentsOfURL:(NSURL*)aURL-(BOOL)writeToFile:(NSString*)pathatomically:(BOOL)flag-(BOOL)writeToURL:(NSURL*)aURLatomically:(BOOL)flag



可变字符串对象NSMutableDictionary

NSMutableDictionary用于描述可变字典,是NSDictionary的子类

-(void)setObject:(ObjectType)anObjectforKey:(id<NSCopying>)aKey-(void)removeObjectForKey:(KeyType)aKey-(void)removeAllObjects-(void)removeObjectsForKeys:(NSArray<KeyType>*)keyArray


plist文件

Property list文件是苹果Mac及iOS系统下使用的属性配置文件,是XML格式的文件。

Plist文件可以存放数值、数组、词典等。

Plist文件通常用于存储用户设置,也可用于存储捆绑的信息。

从plist文件中读取内容,使用NSArray、NSDictionary的contentOfFile方法

向plist文件中保存数据,使用NSArray、NSDictionary的writeToFile方法