I have an NSSet of NSManagedObjects whose subclass has a property called "level". The NSSet is supposed to be filtered by "level".
The user finishes a level, then the app checks if an NSManagedObject exists for the next level (indicating that the user had already unlocked that level). It does this by calling a method that filters the set using a predicate and returns the result of a call to "anyObject".
Note: levels are numbered starting with 0.
Here's my code:
However, my debugger indicates that objectToReturn is set by anyObject to the NSManagedObject that corresponds to the first level. Therefore, even when level=1, objectToReturn != nil, meaning the aforementioned check does not fail.
Is filteredSetUsingPredicate supposed to return anything, even if nothing in the set meets the predicate?
The user finishes a level, then the app checks if an NSManagedObject exists for the next level (indicating that the user had already unlocked that level). It does this by calling a method that filters the set using a predicate and returns the result of a call to "anyObject".
Note: levels are numbered starting with 0.
Here's my code:
Code:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"level==%f",level];
NSSet *filteredSet = [self.places filteredSetUsingPredicate:predicate];
NSManagedObject *objectToReturn = [filteredSet anyObject];
Is filteredSetUsingPredicate supposed to return anything, even if nothing in the set meets the predicate?