ShengHuaWu ShengHuaWu - 1 year ago 109
Objective-C Question

How to store an ALAsset object as an attribute of a NSManagedObject

My application allows user to upload photos from the camera roll. Since I use NSManagedObject to manage the uploading photos, I want to store an ALAsset object as an attribute of NSManagedObject. I have tried to set the attribute type to "Transformable" and set the transformable name to "NSUnarchiveFromDataTransformerName". However, my application crashed when storing ALAsset. Could someone share how to store ALAsset object as an attribute of a NSManagedObject. Thanks a lot!

Answer Source

Instead of storing the ALAsset object, you can store the url of that asset.

You can fetch the url for the asset object:

    [asset.defaultRepresentation.url absoluteString]

From the url, you can fetch the asset object whenever you need.

by calling this method :

    [assetslibrary assetForURL:assetURL resultBlock:assetResultBlock failureBlock:failureBlock];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download