Cloudkit , 无法识别的选择器

Cloudkit , Unrecognized Selector

[CKRecord stringForKey:]: 无法识别的选择器发送到实例 0x17412ece0'

我收到上述错误,但不确定我需要做什么来更正它。我正在 运行 查询 return CKAssets 到集合视图中以显示图片。我希望两个文本字段匹配,并且当它们匹配时关联的图像填充视图。有人有什么建议吗?

    @IBOutlet var myCollectionView: UICollectionView!
let reuseIdentifier = "MyCell"

var matchedSelfie = [String]()

override func viewDidLoad() {
    super.viewDidLoad()
    let database = CKContainer.defaultContainer().publicCloudDatabase
    let container = CKContainer.defaultContainer()
    let publicDB = container.publicCloudDatabase
    let data = CKRecord(recordType: "theUsers")
    let text1 = data.valueForKey("text1")
    let text2 = data.valueForKey("text2")
    var predicate = NSPredicate(value: text1 === text2)
    let myQuery = CKQuery(recordType: "theUsers", predicate: predicate)

    var mySelfie = matchedSelfie

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

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

                    mySelfie.append(aselfie)
                    return ()
                }

            }}}

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}



override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
    //#warning Incomplete method implementation -- Return the number of sections
    return 1
}


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    //#warning Incomplete method implementation -- Return the number of items in the section
    return matchedSelfie.count
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = myCollectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as CollectionViewCell
    let image = UIImage(named: matchedSelfie[indexPath.row])
    cell.matchedSelfie.image = image
    // Configure the cell

    return cell
}

错误说明了这一点。密钥 selfie 不存在。

您必须检查密钥是否真的存在。如果密钥存在,您可以尝试使用 objectForKey:

let aselfie = record.objectForKey("selfie") as String