Pankaj Jangid
Pankaj Jangid

Reputation: 832

How to store PHAsset into Core Data

I am selecting images from Photos and iCloud. I want to store PHAsset into core data. How can we store PHAsset into core data?.

Before that I was storing local image URL, but some local urls are private.So I was not able to fetch image.

Upvotes: 0

Views: 1060

Answers (1)

f.overflow
f.overflow

Reputation: 298

One possible way is to turn the image into data and add that data to your managedObject.
Your attribute type for the attribute in the X should be set to "binary data".

Otherwise (e.g. if you want to interact with the original file from Photos or iCloud) you could save the local identifier, and then use

fetchAssetsWithLocalIdentifiers

to get the image again after receiving the identifier from your managedObject.

Hope that helps you!

Upvotes: 3

Related Questions