开发者

Searching within a folder structure in Core Data

I have a Core Data model co开发者_StackOverflow中文版nsisting of folders and items. A folder may contain either subfolders or items. Each item has a "Folder" relationship. Each folder has a "Parent" relationship (which may be nil). Inverse relationships are also defined.

Say I have the following structure:

FOLDER 1
  SUBFOLDER 1.1
    ITEM 1 = "abc"
  SUBFOLDER 1.2
    SUBFOLDER 1.2.1
      ITEM 2 = "abc"
FOLDER 2
  ITEM 3 = "abc"

What I would like to do is to search for "abc" in FOLDER 1 only, so that I'll get ITEM 1 and ITEM 2 but not ITEM 3.

Is there a predicate that I can use for this, or do I have to filter the results myself after I get them from Core Data?


Can you search for your item's parent name if it contains "FOLDER 1", that will cover all subfolders of FOLDER 1, but not FOLDER 2.

See here for how to create an NSPredicate for string comparisons.

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜