新聞中心
字典對(duì)象NSDictionary
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了開州免費(fèi)建站歡迎大家使用!
NSDictionary用于描述字典對(duì)象,數(shù)組的下標(biāo)是整型數(shù),字典的下標(biāo)是字符串類型的key
創(chuàng)建:
+ (instancetype)dictionary + (instancetype)dictionaryWithObject:(ObjectType)anObject forKey:(id)aKey + (instancetype)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray > *)keys + (instancetype)dictionaryWithObjectsAndKeys:(id)firstObject, ...
字面值:
NSDictionary * dict = @{@"key1":@"value1", @"key2":@"value2”}; //常量方式
基本操作:
@property(readonly) NSUInteger count - (ObjectType)objectForKey:(KeyType)aKey
文件/URL相關(guān):
+ (NSDictionary*)dictionaryWithContentsOfFile:(NSString *)path + (NSDictionary *)dictionaryWithContentsOfURL:(NSURL *)aURL - (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag - (BOOL)writeToURL:(NSURL *)aURL atomically:(BOOL)flag
可變字符串對(duì)象NSMutableDictionary
NSMutableDictionary用于描述可變字典,是NSDictionary的子類
- (void)setObject:(ObjectType)anObject forKey:(id)aKey - (void)removeObjectForKey:(KeyType)aKey - (void)removeAllObjects - (void)removeObjectsForKeys:(NSArray *)keyArray
plist文件
Property list文件是蘋果Mac及iOS系統(tǒng)下使用的屬性配置文件,是XML格式的文件。
Plist文件可以存放數(shù)值、數(shù)組、詞典等。
Plist文件通常用于存儲(chǔ)用戶設(shè)置,也可用于存儲(chǔ)捆綁的信息。
從plist文件中讀取內(nèi)容,使用NSArray、NSDictionary的contentOfFile方法
向plist文件中保存數(shù)據(jù),使用NSArray、NSDictionary的writeToFile方法
文章名稱:Foundation框架(4)字典對(duì)象及plist文件
網(wǎng)站路徑:http://fisionsoft.com.cn/article/gsdige.html