开发者

Querying a 'column' in core data

开发者 https://www.devze.com 2022-12-17 13:15 出处:网络
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\".

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:@"files.@unionOfSet.filename"];

... but i've been having no luck getting it to go, and Apple's set operations g开发者_运维技巧uide has got me stumped.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号