我希望能够通过SwiftyUserDefaults保存包含UIImages的数组,cardImages
。Persist Array of Swift
期望的行为
这里是确切所需的行为:
Save an array of UIImages to NSUserDefaults via the SwiftyUserDefault library
Retrieve the images later
代码这被剥离下来到很少的代码
var newPhotoKey = DefaultsKey<NSArray>("image")//Setting up the SwiftyUserDefaults Persisted Array
cardImages = [(UIImage(named: "MyImageName.jpg")!)] //This array contains the default value, and will fill up with more
Defaults[theKeyForStoringThisArray] = cardImages //This is the persisted array in which the array full of images should be stored. WHERE THE ERROR HAPPENS
var arrayToRetreiveWith = Defaults[theKeyForStoringThisArray] as! [UIImage] //To Retreive
错误
我得到以下错误:
Attempt to set a non-property-list object ( ", {300, 300}" ) as an NSUserDefaults/CFPreferences value for key image *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object ( ", {300, 300}" ) for key image'
谢谢!