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

1.9k views Asked by At

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' 
3

There are 3 answers

1
emp On BEST ANSWER

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.

1
TechZen On

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.

0
theory On

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.