I'm running into a crash with the following code. self.items
is an NSArray
of NSManagedObjects
with an "id"
attribute of type String:
NSMutableArray *allIDs = [self.items mutableArrayValueForKey:@"id"];
NSArray *presentIDs = // a subset of allIDs
[allIDs removeObjectsInArray:presentIDs];
Here is the crash message:
'Unacceptable type of value for attribute: property = "id"; desired type = NSString; given type = __NSArrayM; value = ....
Printing it out in debugger reveals that allID
is a NSKeyValueSlowMutableArray
instead of __NSArrayM
for a regular NSMutableArray
.
So I changed it to this and it works:
NSMutableArray *allIDs = [[self.items valueForKey:@"id"] mutableCopy];
What is the difference between these two calls that would make the former crash but the latter work? I suspect it's something to do with KVO and proxy collections but don't quite understand it.