我正在尝试将存储为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:获取aString?CKRecord

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操作时,实际上是在创建matchedself的副本。

关于ios - 输入anyObject?不符合“StringLiteralConvertible”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28270290/

10-12 05:51