Last active
November 30, 2015 18:24
-
-
Save jamesktan/1c4ba3ea2702a03ee29a to your computer and use it in GitHub Desktop.
iOS : Core Data - Get Unique Attributes from Core Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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