0

NSDictionary オブジェクトを含む NSArray があります。

値の選択に基づいてオブジェクトをフィルター処理する必要があるため、フィルター処理する値の配列を作成し、predicatewithformat を使用してオブジェクトの配列をフィードしました。

これは一種の機能ですが、奇妙なことに、空の配列を返す必要があることがわかっている状況では、そこにあってはならない単一のオブジェクトを取得しています。

フィルター値の配列の値をログアウトしました。オブジェクトの id_str に対応するキーが含まれていることがはっきりとわかるので、返されるべきではありません。

以下は私が使用しているコードです。私が間違っている場所のポインタは非常に役に立ちます!

                 //Create new fetch request
             NSFetchRequest *request = [[NSFetchRequest alloc] init];

             //Set new predicate to only fetch tweets that have been favourited
             NSPredicate *filterFavourite = [NSPredicate predicateWithFormat:@"favouriteTweet == 'YES'"];

             //Setup the Request
             [request setEntity:[NSEntityDescription entityForName:@"Tweet" inManagedObjectContext:_managedObjectContext]];

             //Assign the predicate to the fetch request
             [request setPredicate:filterFavourite];
             NSError *error = nil;

             //Create an array from the returned objects
             NSArray *favouriteTweets = [_managedObjectContext executeFetchRequest:request error:&error];
             NSAssert2(favouriteTweets != nil && error == nil, @"Error fetching events: %@\n%@", [error localizedDescription], [error userInfo]);

             //Create a new array containing just the tweet ID's we are looking for
             NSArray *favouriteTweetsID = [favouriteTweets valueForKey:@"tweetID"];

             NSLog(@"%@", favouriteTweetsID);

             //Create a new predicate which will take our array of tweet ID's
             NSPredicate *filterFavouritsearchPredicate = [NSPredicate predicateWithFormat:@"(id_str != %@)" argumentArray:favouriteTweetsID];

             //Filter our array of tweet dictionary objects using the array of tweet id's we created
             NSArray *filteredTweets = [self.timelineStatuses filteredArrayUsingPredicate:filterFavouritsearchPredicate];

             //Send those tweets out to be processed and added to core data
            [self processNewTweets:filteredTweets];

             NSLog(@"Update Favoutited Tweets: %@", filteredTweets);
4

1 に答える 1

4

これはおそらくあなたが意図したことをしていません:

[NSPredicate predicateWithFormat:@"(id_str != %@)" argumentArray:favouriteTweetsID];

と同等です

[NSPredicate predicateWithFormat:@"(id_str != %@)", id1, id2, ... idN];

ここで、id1、id2、...、idN は の要素ですfavouriteTweetsID。フォーマット文字列にはフォーマット指定子が 1 つしかないため、最初の要素以外はすべて無視され、

[NSPredicate predicateWithFormat:@"(id_str != %@)", id1];

id_strがどの配列要素とも等しくないすべてのオブジェクトをフィルタリングする場合は、次を使用します。

[NSPredicate predicateWithFormat:@"NOT id_str IN %@", favouriteTweetsID];
于 2013-07-04T17:04:36.887 に答える