Extract attributes from NSManagedObject array.

Posted by Pavel Peroutka on Stack Overflow See other posts from Stack Overflow or by Pavel Peroutka
Published on 2010-04-27T05:42:40Z Indexed on 2010/04/27 5:43 UTC
Read the original article Hit count: 332

Filed under:

NSFetchRequest *req = [NSFetchRequest init];

NSEntityDescription *descr = [NSEntityDescription entityForName:@"City" inManagedObjectContext:context]; [req setEntity:descr];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"streetName" ascending:YES]; [req setSortDescriptors:[NSArray arrayWithObject:sort]]; [sort release];

//fetch

NSError *error; NSArray *result = [context executeFetchRequest:req error:&error];

//extract names

NSMutableArray *streets = [[NSMutableArray alloc] init];

for () { ??? = [array objectAtIndex:i];
[streets addObject:name];

}

I expected Core Data to be little more intuitive. I am new in it and I could use some help. I fetched all objects(rows) from the entity (table) City. Now I have an array of objects. From the array I need to extract the attribute “streetName” to an array which will feed the picker. I figured I need to do it in the loop but I could not figure out the way to do it. Please help.

I have a background with SQL but Core Data is still a big mystery to me. Is there any publication which would take a SQL statement and show comparable Core Data syntax?

Thanks.

© Stack Overflow or respective owner

Related posts about iphone