我有一个“bookshelf”数组,其中包含四个NSMutableDictionary“book”(其中包含三个属性),我的问题是如何访问“book”字典的hasBeenRead标志/属性以找出哪本书没有读?
书(S):
{
"title":"Winnie-the-Pooh",
"author":"A.A. Milne"
"hasBeenRead": No
}
书架:
[
{
"title":"Jungle Book",
"author":"Rudyard Kipling",
"hasBeenRead":"Yes"
},
{
"title":"Winnie-the-Pooh",
"author":"A.A. Milne",
"hasBeenRead":"No"
},
{
"title":"Alice In Wonderland",
"author":"Lewis Carroll",
"hasBeenRead":"Yes"
}
]
我可以获得Book NSMutableDictionary:
for (NSString* readBook in self.bookshelf) {
NSLog(@"Books: %@", readBook);
}
感谢。
答案 0 :(得分:0)
怎么样:
for (NSDictionary* readBook in self.bookshelf) {
NSLog(@"Books: %@", [readBook objectForKey:@"hasBeenRead"]);
}
答案 1 :(得分:0)
您可以过滤书架使用NSPredicate
NSString *hasBeenReadFlag = @"No";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.hasBeeRead == %@", hasBeenReadFlag];
NSArray *filtered = [self.bookshelf filteredArrayUsingPredicate:predicate];
NSLog(@"%@", filtered);
现在你可以得到所有书还没有被阅读
此致