我是Swift编程的新手,但是可以存储对UIImage
的引用,而不是UIImage
本身。考虑某种图像标识符,它是一个字符串,以后需要UIImage
本身时可以调用它。
我希望能够存储[PhotoAlbum]
的数组。我本打算对数组进行编码,但由于UIImage
无法编码,因此无法进行编码。
import Foundation
import UIKit
struct PhotoAlbum {
var title: String
var thumbnail: UIImage?
init(title: String, thumbnail: UIImage?) {
self.title = title
self.thumbnail = thumbnail
}
}
我最终使用了PHAsset并存储了localIdentifier。
var new_images: Array<Any> = []
for photo in photos {
new_images.append(photo.localIdentifier)
}