How can I prevent duplicate results in a fetch from CoreData?
I'm running a very simple fetch unitType like $GIVEN_TYPE
with a substitution dictionary, it's returning consistently 40 objects when there should be about 5. It seems like it's repeating the same results in different order, like permutations of them or something, except there are 120 permutations of 5 not 40.
It returns :
A B C D E
A E D C B
B A C D E
E D B C A
C E B D A
A D E C B
C D B E A
B E A C D
consistently every time.
I'm 99% sure there aren't all these repetitions of the same instances, I would check to make sure but I'm not really sure how to check, I had expected this query to return one of each..
Any help is appreciated in narrowing this down.
Update
Here's the basic code I'm using for the lookup, the fetch request is in xcode, but it's a one-liner, it just says unitType like $GIVEN_TYPE
NSArray * results = nil;
NSManagedObjectModel * model = [[cont persistentStoreCoordinator] managedObjectMode开发者_运维百科l];
NSDictionary * substDict = [NSDictionary dictionaryWithObject:name forKey:@"GIVEN_NAME"];
NSFetchRequest * fetReq = [model fetchRequestFromTemplateWithName:@"UnitLookup" substitutionVariables:substDict];
results = [cont executeFetchRequest:fetReq error:&e];
@macworth - I did check now with Base, and I was right that there are only 5 object with unitType equal to the value I put in (tried changing like to ==) I was pretty sure, because I'm populating the database myself at the start of the test, and I tried it repeatedly after deleting the app from the simulator, and re-running.
You can open the CoreData database in any SQLLight browser - Base is a good one.
Go find the iPhone simulator directory, go to the application directory inside there, and look for the SQLite database inside. Open it in a SQLlite browser and look through the tables until you find the one representing the entity in question, and see how many objects you have.
精彩评论