开发者

setPropertiesToFetch doesn't work as expected

开发者 https://www.devze.com 2022-12-09 14:54 出处:网络
I want a list of unique contacts that I\'ve stored with core data. NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Post" inManagedObjectContext:[self managedObj

I want a list of unique contacts that I've stored with core data.

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Post" inManagedObjectContext:[self managedObjectContext]];
        NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
        [request setEntity:entityDescription];
        
        
        NSDictionary *entityProperties = [entityDescription propertiesByName];
        
        [request setPropertiesToFetch:[NSArray arra开发者_JAVA百科yWithObject:[entityProperties objectForKey:@"contactID"]]];
        [request setReturnsDistinctResults:YES];
        
        NSError *error = nil;
        NSMutableArray *retValue = [[[self.managedObjectContext executeFetchRequest:request error:&error] mutableCopy] autorelease];

The result is always the same with or without the setPropertiesToFetch, so I guess there is something wrong with it, but I can't figure out what it is. Can someone help me?


Did you set your fetch result type to NSDictionaryResultType? The documentation says setPropertiesToFetch: only works when result type == NSDictionaryResultType

.n

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号