ios - Get all results of a NSFetchRequest in an NSArray -


in app thing abtain specific value entity

nsmanagedobjectcontext *context = [[self sharedappdelegate] managedobjectcontext]; nserror *error = nil; nsfetchrequest *req = [nsfetchrequest fetchrequestwithentityname:@"structure"]; [req setpropertiestofetch:@[@"id_str"]]; [req setresulttype:nsdictionaryresulttype];  nsarray *id_str_bd = [context executefetchrequest:req error:&error]; 

int way obtain nsarray of nsdictionaryies want directly array of values. what's fast way obtain without loops?

i agree tom. values?

anyway, can accomplish through kvc. example,

nsfetchrequest* fetchrequest = [nsfetchrequest fetchrequestwithentityname:@"structure"]; [fetchrequest setpropertiestofetch:@[@"id_str"]];  nsarray* results = [[self managedobjectcontext] executefetchrequest:fetchrequest error:nil]; nsarray* ids = [results valueforkey:@"id_str"];  nslog(@"%@", ids); 

notes

  • do not pass nil error. always check possible error (for sake of simplicity don't use in code snippet)
  • i rename id_str idstructure

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -