1

I've searched far and wide to find a solution to this problem. All of my attempts result in 0 results. Here is the general data structures:

Core Data Entity A {
  stringAttribute string
  ....
  transformableAttribute(NSArray of NSString objects) keywords
}

where keywords = [NSArray arrayWithObjects:@"string 1",@"string 2",@"string 3",nil]

I'm trying to run a predicate to search the NSArray transformable attribute.

I've tried the following against entity A. The core data store is a sqlite store.

NSString *term = @"string 1";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY keywords like[cd] %@", term];

----> Results in 0 matches

NSArray *termArray = [NSArray arrayWithObject:@"string 1"];
NSPredicate *predicate = [NSPredicate predicateWithFormat@"ANY keywords in %@", termArray];

----> Results in 0 matches

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(keywords, $x, $x like %@).@count > 0", term]

----> Results in an error that a non-relationship cannot be a subquery collection

I've tried some permutations of the above, but still no results. Any advice? Is this possible with Core data?

Thanks!

2
  • I think life would be easier if you made your array of strings a separate entity and use a relationship to connect them. What you are trying to do is easy if implemented like that. Commented Jan 13, 2012 at 4:10
  • Yeah, I think a separate entity is best, just like in SQL. I was hoping to avoid doing a migration, but I can't find a better way. I'm using fetchedresutlscontrollers, which require fetching by predicate, and I can't filter manually. Commented Jan 13, 2012 at 6:28

1 Answer 1

0

I'm not use with transformableAttribute that is an element of Core Data that I haven't got into, but if I recall you can't predicate on them. (so If I'm wrong please some one call me on this)

But when I see that your transformableAttribute is an array of string I just want to say why do you want an array in a database?

Why not make a relationship? A one to many relationship if your array can have different number of string.

Core Data is an abstraction of a Data Base, in a DB you don't use array, you use tables. That would probably simplify your life and make the fetching possible.

Sign up to request clarification or add additional context in comments.

1 Comment

This seems to be true. When I do a direct search on NSPredicate with transformableAttribute, many folks have found that you can't do it. The transformable attribute is stored in the DB as binary data, so doing a SQL query on it won't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.