Skip to content

Instantly share code, notes, and snippets.

@jamesktan
Last active November 30, 2015 18:24
Show Gist options
  • Save jamesktan/1c4ba3ea2702a03ee29a to your computer and use it in GitHub Desktop.
Save jamesktan/1c4ba3ea2702a03ee29a to your computer and use it in GitHub Desktop.
iOS : Core Data - Get Unique Attributes from Core Data
NSManagedObjectContext *context = <#Get the context#>;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"<#Entity name#>" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:@[@"<#Attribute name#>"]];
// Execute the fetch.
NSError *error;
id requestedValue = nil;
NSArray *objects = [context executeFetchRequest:request error:&error];
if (objects == nil) {
// Handle the error.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment