简体   繁体   中英

Core data entity attribute values to NSMutableArray iPhone

I am using this code to fetch the core data results:

-(void)getData {

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Favouritesdata" inManagedObjectContext:context];

NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setFetchBatchSize:20];

[request setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"licenseplate" ascending:NO];

NSArray *newArray = [[NSArray alloc]initWithObjects:sort, nil];

[request setSortDescriptors:newArray];

NSError *error;
results = [[context executeFetchRequest:request error:&error] mutableCopy];

NSLog(@"results::::: %@", results);

[self setLicensePlateArray:results];

[self.favouritesTable reloadData];

}

Here in this entity Favouritesdata, I have an attribute with the name of license plate, I want to get this attribute values to NSMutableArray.

How can I get these values?

You can use NSPredicate and directly get the value by passing the predicate in the request. Refer this link for more information http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSPredicate_Class/Reference/NSPredicate.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM