开发者

Core Data With NSData Attribute

开发者 https://www.devze.com 2023-03-28 17:58 出处:网络
I am working on a Core Databased iOS application , in which i stored an array strings in coredata as NSData(binary data).

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 if name 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

0

精彩评论

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

关注公众号