tags:

views:

67

answers:

1
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.

A: 

It's very simple because of key-value coding:

NSArray *streets = [result valueForKey:@"streetName"];
Skie