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

风格不统一 提交于 2019-12-09 10:49:42

问题


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' 

回答1:


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.




回答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.




回答3:


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.



来源:https://stackoverflow.com/questions/7930427/error-uiimage-deleteexternalreferencefrompermanentlocation-unrecognized-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!