re: NSExpression with constant NSData value crashes Core Data
re: NSExpression with constant NSData value crashes Core Data
- Subject: re: NSExpression with constant NSData value crashes Core Data
- From: Ben Trumbull <email@hidden>
- Date: Fri, 22 May 2009 13:54:12 -0700
On 2009 May 17, at 15:10, Ben Trumbull wrote:
Core Data supports == and != searches against binary data. You
should be able to just use a predicate like:
[NSPredicate predicateWithFormat:@"myTransformableAttribute = %@",
myGuidObject]
and have it "just work".
Read the above carefully!
myGuidObject is an NSData, right? So when you make that predicate
with %@, it becomes a string description, complete with angle brackets
and a whitespace separating each group the four bytes. Core Data is
actually comparing the ^descriptions^ of NSData objects. Yuck!!
Uhm, No. %@ is the vararg specifier for an NSObject. -
stringWithFormat: turns that into a string. Because -
stringWithFormat: turns everything into a string. Kinda the point.
-predicateWithFormat: does NOT call -description randomly. Predicates
are trees of first class objects, like an AST for a query. It does
not turn objects into their textual representation before comparison.
Result: It worked fine with the XML store (Why??). But when I switch
to the SQLite store, it crashes when Core Data sends a -UTF8String
message to the data object -- because it's expecting a damned
description string. Took me several hours before I finally read Ben's
post very carefully and figured out why it was doing that.
This bug was fixed in 10.5.7
- Ben
_______________________________________________
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