
依資料型態選擇不同,使用不同類別來開啟。
* Array範例:
NSString *plistPath = [[[NSBundle mainBundle] bundle]
stringByAppendingPathComponent:@"MyPlist.plist"];
NSArray *plistArray = [NSArray arrayWithContentsOfFile: plistPath]; //讀取plist file
NSString *propertyString = [plistArray objectAtIndex:2]; //取得字串物件
NSInteger *propertyInt = [[plistArray objectAtIndex:2] intValue]; //取得整數值
Bool propertyBool = [[plistArray objectAtIndex:2] boolValue]; //取得布林值
float propertyFloat = [[plistArray objectAtIndex:2] floatValue]; //取得浮點數值
[plistArray writeToFile:plistPath atomically:NO]; //回寫plist file
* Dictionary範例:
NSString *plistPath = [[[NSBundle mainBundle] bundle]
stringByAppendingPathComponent:@"MyPlist.plist"];
NSDictionary *plistDic = [NSDictionary dictionaryWithContentsOfFile: plistPath]; //讀取plist file
NSString *propertyString = [plistDic objectForKey:@"姓名"]; //取得字串物件
NSInteger *propertyInt = [[plistDic objectForKey:@"年齡"] intValue]; //取得整數值
Bool propertyBool = [[plistDic objectForKey:@"已婚"] boolValue]; //取得布林值
float propertyFloat = [[plistDic objectForKey:@"身高"] floatValue]; //取得浮點數
[plistDic writeToFile:plistPath atomically:NO]; //回寫plist file
沒有留言:
張貼留言