Cloudkit,无法识别的选择器

时间:2015-02-02 22:27:02

标签: ios swift uicollectionview cloudkit

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

我收到了上述错误,并且不确定我需要做些什么来纠正它。我正在运行一个查询,将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
}

1 个答案:

答案 0 :(得分:0)

错误说明了。键selfie不存在。

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

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