I am working on a Core Data
based iOS application , in which i stored an array strings in coredata as NSData
(binary data).
While fetching the data , how can i write a NSPredicate
which will only retrieve the result with NSData
value contain given string .
if name
attribute is a string then i can write a predicate like below.
NSString *inputName = @"bbb";
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"name = %@",inputName];
my question is
what will be the predicate ifname
is NSData
and this NSData
from
NSArray *anArray = [NSArray arrayWithObjects:@"aaa",@"bbb",@"ccc",nil];
NSData *arrayData = [NSArchiver开发者_运维技巧 archivedDataWithRootObject:anArray];
arrayData
is stored as name
attribute in Core Data .
I hope this information is enough to understand my problem. Thanks in advance.
i found the answer ..converted NSArray
to NSSet
and store it in entity
If I understand your question and subsequent comments correctly, and you are using an array stored as data to represent a hierarchical relationship then you are clearly not using Core Data as designed.
Instead, I recommend you create a separate entity to represent the employees and then set up a relationship between them and the supervisor?
Although it's not iOS specific, this tutorial by Apple demonstrates that very concept.
Based on your comments, I think you need to revisit your schema. If you have a one-many relationship between Supervisor & Employee (Many employees can have the same supervisor), you should create an Entity Employee
, and add an attribute supervisorID to it. Then you can query your Employee table with something like- where supervisorID="123"
.
If you cannot redesign your schema, you can convert NSData to NSString & save it in CoreData using -initWithData:encoding:
.
HTH,
Akshay
精彩评论