views:

52

answers:

1

I have a core data entity named "Folder". Each "Folder" has a 1-to-many relationship with the entity "File", and each file contains the field "filename".

What is a succinct way of producing an array of all of the filenames for a given folder? I expected it to be something like:

NSManagedObject* folder = [self getSomeFolder];
NSArray* files = [folder valueForKey:@"[email protected]"];

... but i've been having no luck getting it to go, and Apple's set operations guide has got me stumped.

+4  A: 

Your solution is mostly correct, but you need to use -valueForKeyPath: instead of -valueForKey:. -valueForKey: is optimized for keys that do not contain multiple elements (separated by .).

Barry Wark
Cheers mate, probably saved me a lot of frustration!
Scott
No worries. This one bites me at least once a project.
Barry Wark
Clarifying: A key path is one or more keys, separated by ‘.’. A single key cannot contain a ‘.’, because that would form a key path of two keys. Either method will work with a single key, but for a key path, you must use `valueForKeyPath:`.
Peter Hosey