views:

109

answers:

1

Bit of Background info, I'm using An NSOutlineView with Core Data. This Is What I'm trying to do:

  1. Retrieve All The objects from the Outline Views Tree Controller.

  2. Retrieve the 'name' Property (Core Data) from each of these objects as a String.

  3. Finally store the Strings of the 'name' Property from all the Objects in an NSArray.

For extra help, here is a Picture of my Core Data Model, http://snapplr.com/xqxv

Is this possible?

A: 

You don't need to go to the treeController to get your objects, you can query your ManagedObjectContext directly.

You essentially create and execute a fetch request, which returns an NSArray. You set the predicate for the fetch in this process as well, so if you are using it to try and filter your data this is useful as well.

Here is the example from the Apple Documentation on Fetching Managed Objects.

Abizern
Wow! Thanks! One question, how do I retrieve just the Strings of the 'name' property for each of the objects?
Joshua
You have an array of objects (Step1) Enumerate through the objects to get the name property for each one (Step2) append each result to an array (Step3)
Abizern
So far, I have this code, http://snapplr.com/wxvg, which will Fetch the Managed Objects. How do I enumerate through them to get the name property?
Joshua
Have you even looked at the NSArray documentation to see if that helps? There's even a method that compacts steps 2 and 3 for you.
Abizern
Is it one of these, `enumerateObjectsUsingBlock:` `enumerateObjectsWithOptions:usingBlock:` `enumerateObjectsAtIndexes:options:usingBlock:` ?
Joshua
I give up - `NSArray *namesArray = [array valueForKey:@"name"];`
Abizern
Ah. I thought it had 'enumarate' in it. Thanks!
Joshua