Error: -[UIImage _deleteExternalReferenceFromPermanentLocation] unrecognized selector sent to instance
Asked Answered
I

3

7

When I delete a managed object that contains image, stored as transformable value in external record, then I got crash and this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage _deleteExternalReferenceFromPermanentLocation]: unrecognized selector sent to instance 0xde49360' 
Iorgos answered 28/10, 2011 at 14:16 Comment(0)
F
12

I answered to something similar in the Apple Developer forums.
I am guessing you have the external storage checkbox selected on that field in the data modeller.

There is a bug in that can be worked around. I did it like this:
Once you have updated your data, and saved the context, any attempt to delete it will raise this 'unrecognized selector' exception.
To force the correct object that can respond to the _deleteExternalReferenceFromPermanentLocation message, do this:

[[self managedObjectContext] refreshObject:myobject mergeChanges:NO];

The object turns into a fault. When you next access it, or delete it, the external data is deleted as expected as the correct object that wraps your external data will be pulled from the store and will correctly respond to _deleteExternalReferenceFromPermanentLocation.

Fellatio answered 3/11, 2011 at 20:27 Comment(1)
Is this also a problem for the "Binary Data" Core Data type (with "Allows External Storage" checked), or only a problem for "Transformable"?Libradalibrarian
Y
2

The means that UIImage does not respond to the:

_deleteExternalReferenceFromPermanentLocation

…selector which means that UIImage doesn't implement that particular method. This appears to be one of the private methods that Core Data uses to store large chunks of data in external files. That's a function only available in iOS 5.

In this case there are two most likely causes:

(1) You've confused a UIImage object with a managed object or vice versa such that a message intended for one class is sent to another (that is the most common cause of this class of error.)

(2) You trying to run code compiled for iOS 5 under an earlier iOS either in the simulator or the device.

Yester answered 29/10, 2011 at 16:36 Comment(1)
I have transformable attribute, in which I store UIImage through NSValueTransformer... As I understand I need to change this attribute to NSData to avoid this error messageIorgos
D
2

I ran into this issue, too, with an NSDate core data attribute. I don't need it to be stored externally, but could not find any checkbox to unset (Xcode 4.2). However, it was clearly there when I acked for it:

> ack -aiQ external Collections.xcdatamodeld
Collections.xcdatamodeld/Collections.xcdatamodel/contents
12:        <attribute name="createdAt" attributeType="Date" allowsExternalBinaryDataStorage="YES" indexed="YES" syncable="YES"/>

So I just deleted and re-created that attribute with the same name. The allowsExternalBinaryDataStorage XML attribute went away and so did my crash. I must've inadvertently checked something during a beta release of iOS 5 or something and it just got stuck in the data model, quietly waiting until I tried to delete an object.

Anyway, perhaps this will help other folks who run into what appears to be an iOS bug but don't need the attribute in question to be stored externally.

Demy answered 24/2, 2012 at 5:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.