Note that there are some explanatory texts on larger screens.

plurals
  1. POFiltering NSArray with Predicate leaves extra result?
    primarykey
    data
    text
    <p>I have an NSArray containing NSDictionary objects.</p> <p>I need to filter the objects based on a selection of values, so i have created an array of the values i want to filter by and using a predicatewithformat and feeding it the array of objects.</p> <p>This is kind of working, but weirdly in situations where i know i should be getting an empty array returned i am getting a single object, that shouldn't be there.</p> <p>I have logged out the value of the array of filter values, and i can clearly see that it contains a key which corresponds to the id_str of the object, so it shouldn't be returned.</p> <p>Below is the code i am using, any pointers of where i am going wrong would be very vert helpful!</p> <pre><code> //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:&amp;error]; NSAssert2(favouriteTweets != nil &amp;&amp; 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); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload