Search code examples
iosswiftcocoa-touchnsuserdefaults

Save UIImage array in NSUserDefaults


I want to put a UIImage array into UserDefaults and then retrieve it. After that set the retrieved images in an image view. How can I do that?


Solution

  • You can easily save your image in documentDirectory as below:

    let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first let fileURL = documentDirectory?.appendingPathComponent(yourImageName)

    and then, you can give your image to UserDefaults