字典對象NSDictionary
NSDictionary用于描述字典對象,數組的下標是整型數,字典的下標是字符串類型的key
創建:
+ (instancetype)dictionary + (instancetype)dictionaryWithObject:(ObjectType)anObject forKey:(id<NSCopying>)aKey + (instancetype)dictionaryWithObjects:(NSArray<ObjectType> *)objects forKeys:(NSArray<id<NSCopying>> *)keys + (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ...
字面值:
NSDictionary * dict = @{@"key1":@"value1", @"key2":@"value2”}; //常量方式基本操作:
@property(readonly) NSUInteger count - (ObjectType)objectForKey:(KeyType)aKey
文件/URL相關:
+ (NSDictionary<KeyType,ObjectType> *)dictionaryWithContentsOfFile:(NSString *)path + (NSDictionary<KeyType,ObjectType> *)dictionaryWithContentsOfURL:(NSURL *)aURL - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag - (BOOL)writeToURL:(NSURL *)aURL atomically:(BOOL)flag
可變字符串對象NSMutableDictionary
NSMutableDictionary用于描述可變字典,是NSDictionary的子類
- (void)setObject:(ObjectType)anObject forKey:(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方法
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。