我希望能夠通過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'
謝謝!