Spindler
Spindler

Reputation: 75

In Core Data, how do I access a specific attribute of every managed object (instance) of a given entity?

This is the Core Data object model I am working with (I am a new user, so I can't post pictures directly):

http://i965.photobucket.com/albums/ae134/spindler77/Screenshot2010-07-26at112231AM.png

All I am trying to do right now is to populate a UITableView with the "className" of every myClass instance the user has created and saved.

My code for generating the myClass instances is fully functioning, but what I can't figure out is how to extract the "className" attribute (to put in my tableview cells) once I have fetched the myClass objects. I have read and re-read the Apple docs (though I'm sure the "answer" is there somewhere, I'm just having a hard time deciphering it).

I have scoured Core Data tutorials as well. The most helpful one that I found has only gotten me to a point where my managed objects are stored in an array, but I can't figure out how to access the attributes of those objects.

My question: How do I access a specific attribute of every managed object (instance) of a given entity?

Thanks in advance for your help.

-Michael

Upvotes: 0

Views: 324

Answers (1)

David Gelhar
David Gelhar

Reputation: 27900

Once you've fetched all your objects into an NSArray, you can then just iterate through the array, for example using fast enumeration:

for (myClass *cl in array) {
    NSLog(@"Name = %@", cl.className);
}

Upvotes: 1

Related Questions