Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data: How can I use NSPredicate on Transformable?

I want to perform a filtering on a Transformable attribute on Core Data. The Transformer value is actually an NSAttributedString. I tried to set a predicate like below:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(attributedString CONTAINS[cd] %@), _searchString];

It did not work. It certainly works with a String attribute.

I've googled it for a whole day, yet no luck. Can someone tell me how to achieve that? Thanks!

like image 722
steveluoxin Avatar asked Sep 01 '25 22:09

steveluoxin


1 Answers

I want to perform a filtering on a Transformer attribute on Core Data.

If you mean a Core Data "transformable" attribute, you really can't do that. Transformed attributes are simply a collection of bytes when they're stored in Core Data. It's not an attributed string in the persistent store-- it's just ones and zeroes. As a result you can't filter based on the attributed string contents.

Strings work because Core Data saves them as strings. But transformable attributes don't work that way. The only predicate you can use with this attribute is one that checks for nil or non-nil values.

like image 146
Tom Harrington Avatar answered Sep 04 '25 10:09

Tom Harrington