我正在尝试将存储为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 ()
}
}
}
}
}
答案 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的副本。