從plist文件中讀取數據
- (void)readDataFromPlist
{
1.先獲取文件路徑
NSString * filePath = [[NSBundle mainBundle] pathForResource:@"Book" ofType:@"plist"];
2.根據路徑初始化字典對象
self.dic = [NSDictionary dictionaryWithContentsOfFile:filePath];
將不可邊字典變成可變字典
self.addressBook = [NSMutableDictionary dictionaryWithDictionary:_dic];
將字典封裝成對象
(1)從字典中遍歷出key
for (NSString * key in self.dic) {
根據key獲取對應的數組
NSArray * groupArr =self.dic[key];
(5) 創建可變的小數組,存儲封裝的對象
NSMutableArray * newGroupArr = [NSMutableArray array];
(3)獲取小數組中元素(遍歷小數組)
for (NSDictionary * groupDic in groupArr) {
(4)通過字典初始化AddressPerson
AddressPerson * Person = [[AddressPerson alloc]initWithDic:groupDic];
[newGroupArr addObject:Person];//將對象存儲到新的可變數組中
RELEASE_SAFE(Person);
}
將要原來key對應的存儲字典的小數組替換成裝有對象的心得可變的數組
[self.addressBook setObject:newGroupArr forKey:key];
}
取出字典中所有的key
self.orderedKeys= [[self.addressBook allKeys]sortedArrayUsingSelector:@selector(compare:)];
NSLog(@"%@",addressBook);
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。