2015-01-03 4 views
2

NSPredicate를 사용하여 필터링하여 두 세트의 영역 데이터 (및 다른 객체) 간의 차이를 얻으려고하고 있지만 이해하는데 어려움이 있습니다. 내 코드 :RLMResults를 인수로 사용하는 NSPredicate

RLMResults *topStories = [KFXTopStory allObjects]; 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NONE threadId = %@.topStoryId", topStories]; 
RLMResults *objectsToDelete = [KFXThread objectsWithPredicate:predicate]; 

오류 :

*** Terminating app due to uncaught exception 'Invalid predicate', reason: 'Predicate with ANY modifier must compare a KeyPath with RLMArray with a value' 

쿼리는 키 패스가 아닌 값 또 다른 키 패스와 비교해야 함을 명시 것으로 보인다. Realm에서도이 유형의 쿼리가 가능합니까? 그것이 있어야하는 것처럼 보입니다, 그래서 나는 어디서 잘못 될까요? 이것 또는 더 나은 해결책의 어떤 도움든지 최고 일 것입니다 - 감사합니다!

편집 : 물론

, 나는 작동 뭔가를 얻을이 게시 한 직후. 그러나 나는 여전히 더 좋은 방법이 있는지 알고 싶습니다. 근무 코드 : NSSet보다는 배열을 사용

RLMResults *topStories = [KFXTopStory allObjects]; 
NSMutableArray *topStoryIds = [[NSMutableArray alloc] initWithCapacity:100]; 

for (KFXTopStory *story in topStories) { 
    [topStoryIds addObject:story.topStoryId]; 
} 

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (threadId IN %@)", topStoryIds]; 
RLMResults *objectsToDelete = [KFXThread objectsWithPredicate:predicate]; 
+0

배열보다는 NSSet을 사용하면 (순서가 지정된 제품의 중복을 제거하는 데) 아마 빠를 수 있지만 그렇지 않은 경우 솔루션이 현재 가장 적합합니다. (http://stackoverflow.com/questions/27728575/realm-cocoa-predicate-to-select-items-not-related와 유사). – segiddins

답변