键入任何对象?不符合 'StringLiteralConvertible'

Type anyObject? does not conform to 'StringLiteralConvertible'

我正在尝试将存储为 CKAssets 的图片添加到集合视图中的数组中,但是我要恢复图像的查询给了我一个我无法弄清楚的错误。谁能帮帮我?

我的代码是:

class Query: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        var matchedSelfie = [String]()

        let database = CKContainer.defaultContainer().publicCloudDatabase
        let container = CKContainer.defaultContainer()
        var publicDB = container.publicCloudDatabase

        let myQuery = CKQuery(recordType: "thecontainer", predicate: NSPredicate(value: "field1" === "field2"))

        var mySelfie = matchedSelfie

        publicDB.performQuery(myQuery, inZoneWithID: nil) {
            results, error in
            if error != nil {
                println(error)

            }
            else {
                for record in results {
                    var aselfie = mySelfie[(
                    aselfie: record.objectForKey("selfie") as String)]

                    mySelfie.append(aselfie)
                    return ()
                }

            }
        }
    }
}

使用stringForKey:获取CKRecord

String?
for record in result c{
    if let aselfie = record.stringForKey("selfie") { //Optional binding
        mySelfie.append(aselfie) //Append to string array
    }
    return ()
}

重要提示: 数组是 Swift 中的结构,因此当您执行 var mySelfie = matchedSelfie.

时实际上是在创建 matchedSelfie 的副本