NSCoding:使Swift类符合NSCoding

时间:2016-05-12 09:21:10

标签: ios swift

我是Swift的新手,我希望在用户从照片库中选择照片后保存图像数据。我正在使用DKImagePickerController(https://github.com/zhangao0086/DKImagePickerController)来选择图像资源。

/**
* 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]?)?
...

以上是DKAsset类的简短快照。下面是使类符合NSCoding的方法。

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

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

但我收到此错误消息"无法转换类型'(图片:UIImage?,info:[NSObject:AnyObject]?)的值?'预期参数类型' AnyObject'"。

我应该如何编码该变量?

0 个答案:

没有答案