输入anyObject?不符合'StringLiteralConvertible'

时间:2015-02-02 02:21:01

标签: ios arrays swift uicollectionview cloudkit

我正在尝试将存储为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 ()
                }

            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

使用stringForKey:获取String?

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

重要提示:数组是Swift中的Structs,因此当您执行var mySelfie = matchedSelfie时,您实际上正在创建matchesSelfie的副本。