ios - Predicate to fetch child files and folders inside a parent folder with coredata -
i have situation apps core-data entities looks
application intends works directory, user can add own files , folders.
i need provide search feature inside folders, user can search files or folders specific values (need iterate through child files , sub folders in sub levels).
can use nspredicate , nsfetchrequest this?
please advice.
if file
, folder
have many things in common ...
change model bit:
- make
node
abstract base class having properties:
identifier
title
relationships:
parent - to-one ->node
- inherit
folder
node
, add relationship:
children - to-many ->>node
- inherit
file
node
, add properties:
mimetype
owner
take account create (under current coredata implementation) single table containing these properties , relationships.
you able search model nodes (file
s , folder
s) title matching given string. use predicate:
[nspredicate predicatewithformat:@"title contains[cd] %@",searchtext]
however ... not complete solution can not limit search given parent node
.
if need limit search, keep parent list each node
adding to-many relationship node
entity called parents
. parents set set upon node
parent
relationship setting, taking new node parent parents
set, coping , adding parent it, setting new node.
this allow more refined search using predicate:
[nspredicate predicatewithformat:@"any parents = %@ , title contains[cd] %@",basenode,searchtext]
this optimised node may point specific parents set without coping on , on again, bit more complex.
you use nested sets or nested intervals implementation ... guess require lot of work on part.
all requests here done on node
entity
Comments
Post a Comment