-1

네 개의 NSMutableDictionary "book"(세 가지 속성이 포함되어 있음)을 포함하는 "bookshelf"배열이 있는데, 내 질문은 어떻게 책을 읽지 않았는지 알아 내기 위해 "book"사전의 hasBeenRead 플래그/속성에 액세스하는 것입니다. ?빠른 열거 형을 사용하여 배열 내부의 NSMutableDictionary 속성에 액세스하려면 어떻게해야합니까?

도서 (들) :

{ 
    "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" 
    } 
] 

내가 책 NSMutableDictionary를 얻을 수 있습니다 :

for (NSString* readBook in self.bookshelf) { 
    NSLog(@"Books: %@", readBook); 
} 

감사합니다.

+0

실제로'readBook'은 문자열입니까? 'class'를 로깅 해보십시오. – Wain

+0

즉, "어떻게 NSArray 및 NSDictionary를 사용합니까?" Objective-C로 프로그래밍하는 사람은 누구나 잘 알고 있어야하는 두 가지 객체. –

답변

0

에 대해 어떻게 :

for (NSDictionary* readBook in self.bookshelf) { 
    NSLog(@"Books: %@", [readBook objectForKey:@"hasBeenRead"]); 

은}

0

당신은 당신의 책장을 사용 지금 NSPredicate

NSString *hasBeenReadFlag = @"No"; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.hasBeeRead == %@", hasBeenReadFlag]; 
NSArray *filtered = [self.bookshelf filteredArrayUsingPredicate:predicate]; 
NSLog(@"%@", filtered); 

모든 책

감사

을 읽지 않은 얻을 수를 필터링 할 수 있습니다

Read more