[英]How to store PHAsset into Core Data
I am selecting images from Photos and iCloud. 我正在从照片和iCloud中选择图像。 I want to store PHAsset into core data. 我想将PHAsset存储到核心数据中。 How can we store PHAsset into core data?. 我们如何将PHAsset存储到核心数据中?
Before that I was storing local image URL, but some local urls are private.So I was not able to fetch image. 在此之前,我存储了本地图像URL,但是一些本地URL是私有的,因此无法获取图像。
One possible way is to turn the image into data and add that data to your managedObject . 一种可能的方法是将图像转换为数据并将该数据添加到您的managedObject中 。
Your attribute type for the attribute in the X should be set to "binary data". 您在X中的属性的属性类型应设置为“二进制数据”。
Otherwise (eg if you want to interact with the original file from Photos or iCloud) you could save the local identifier , and then use 否则(例如,如果您想与Photos或iCloud中的原始文件进行交互),则可以保存本地标识符 ,然后使用
fetchAssetsWithLocalIdentifiers
to get the image again after receiving the identifier from your managedObject . 从您的managedObject接收到标识符后再次获取图像。
Hope that helps you! 希望对您有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.