-1

Hi I'm trying to storing array of images using swift but its not working

i use this for saving

     let defaults = NSUserDefaults.standardUserDefaults()
    defaults.setObject(photos, forKey: header)
    defaults.synchronize()

and this for loading

if let items = defaults.ArrayForKey(header) {
    self.photos = self.photos + items

 }
5
  • You can't store UIImage objects in user defaults, you can however store paths to those images instead. Commented Sep 1, 2016 at 20:55
  • "You can't store UIImage objects in user defaults" You can but you shouldn't. Commented Sep 1, 2016 at 20:57
  • please can you tell me how Commented Sep 1, 2016 at 20:58
  • No, I'm not going to. You shouldn't do it. Commented Sep 1, 2016 at 21:01
  • ok how can i use the path to store array of images Commented Sep 1, 2016 at 21:05

1 Answer 1

0

If photos is an array of UIImage, this code will do nothing:

 defaults.setObject(photos...)

The reason is that UIImage is not a property list type. defaults is a property list. See Apple's docs:

https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/PropertyList.html#//apple_ref/doc/uid/TP40008195-CH44-SW1

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.