Ios 使用Swift将图片发布到iCloud数据库

Ios 使用Swift将图片发布到iCloud数据库,ios,swift,Ios,Swift,我正在尝试拍摄一张照片并将图像上传到iCloud数据库中,但我不断收到错误:键入“UIImage”不符合协议“CKRecordValue” 我正在尝试使用以下代码上载文件: data.setObject(picFile.image, forKey: "picture") 代码行是否有问题,或者我是否缺少其他内容?我必须将其转换为CKAsset。我使用了以下代码: let imageData = UIImageJPEGRepresentation(picFile.image, 1)

我正在尝试拍摄一张照片并将图像上传到iCloud数据库中,但我不断收到错误:键入“UIImage”不符合协议“CKRecordValue”

我正在尝试使用以下代码上载文件:

data.setObject(picFile.image, forKey: "picture")

代码行是否有问题,或者我是否缺少其他内容?

我必须将其转换为CKAsset。我使用了以下代码:

    let imageData = UIImageJPEGRepresentation(picFile.image, 1)
    let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
    let documentDirectory = paths[0] as String
    let myFilePath = documentDirectory.stringByAppendingPathComponent("picture")
    imageData.writeToFile(myFilePath, atomically: true)
    let url = NSURL(fileURLWithPath: myFilePath)
    let asset = CKAsset(fileURL: url)
    data.setObject(asset, forKey: "picture"