0

I am new to Swift and I would like to save the image data after the user has selected their photos from their photo library. I am using DKImagePickerController (https://github.com/zhangao0086/DKImagePickerController) to select the image assets.

/**
* An `DKAsset` object represents a photo or a video managed by the `DKImagePickerController`.
*/
public class DKAsset: NSObject {

/// Returns a UIImage that is appropriate for displaying full screen.
private var fullScreenImage: (image: UIImage?, info: [NSObject : AnyObject]?)?

/// Returns the original image.
private var originalImage: (image: UIImage?, info: [NSObject : AnyObject]?)?
...

Above is a short snapshot of the DKAsset class. Below is what is did to make the class conform to NSCoding.

required convenience init?(coder decoder: NSCoder) {
    let fullScreenImage = decoder.decodeObjectForKey("fullScreenImage") as! UIImage
}    

func encodeWithCoder(aCoder: NSCoder) {
    aCoder.encodeObject(fullScreenImage, forKey: "fullScreenImage")
}

But I get this error message "Cannot convert value of type '(image: UIImage?, info:[NSObject: AnyObject]?)?' to expected argument type 'AnyObject'".

How should I go about encoding that variable?

  • The issue is that `NSCoding` does not support a tuple because it's not a class. – vadian May 12 '16 at 09:36
  • Thanks @vadian! This link may be useful for others looking to answer the same questions. [link](http://stackoverflow.com/questions/28929897/swift-encode-tuple-using-nscoding) – user6324480 May 16 '16 at 05:11

0 Answers0