Re: Referencing NSData's length in a predicate?
Re: Referencing NSData's length in a predicate?
- Subject: Re: Referencing NSData's length in a predicate?
- From: Jerry Krinock <email@hidden>
- Date: Fri, 27 Nov 2009 23:30:31 -0800
On 2009 Nov 27, at 22:03, Dave DeLong wrote:
> I have a Core Data object called "Item". One of its attributes is a binary attribute called "data". I've constructed a fetch request to retrieve all Items based on the length of the data (ex: "data.length <= 1024"). I *know* that I have Items with data less than 1KB, yet when I execute this predicate, it doesn't seem to be returning anything (nothing shows up in my NSTableView of results, while the results of every other fetch request show up just fine).
Are you using the sqlite store?
Is data.length an integer attribute of your 'Item', or are you sending the -length message to an NSData object in the store? In the first case, it should work. In the second case, in my experience, it will not work. See the answer I posted to Ron Aldrich's issue a few hours ago on this list. Core Data predicates are quite limited when fetching from an sqlite store. Just because you can write a predicate and Xcode compiles it doesn't mean it will work.
But then I read this:
> data.length == 414 => returns 0 of 153 items
> data.length != 414=> returns 153 of 153 items
> data.length < 415 => returns 1 item (size 251B)
> data.length <= 414 => returns 1 item (size 251B)
> data.length >= 414 => returns 151 of 153 items
> data.length > 413 => returns 151 of 153 items
I'm not sure if this result is from your array-controller filtering or from your Core Data fetch. My hypothesis is that array-controller filtering will always work and Core Data fetch from sqlite will always return 0 results. But it looks like your results are mixed, so I'm confused.
As I suggested at the beginning, if you *really* want to do this kind of fetch from an sqlite store, 'length' needs to be a "column in the table" (in database lingo). In Core Data lingo, add an integer attribute, 'length'. It seems silly at first, but it's really not that bad. Create a custom setter for 'data', and in this -setData:, invoke -setLength:[data length].
> I haven't found anything in the documentation that indicates that this wouldn't work, so can you help me see what I'm missing?
As I told Ron, you must read between the lines.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden