Ios Cloudkit,无法识别的选择器
[CKRecord stringForKey:]:发送到实例0x17412ece0的选择器无法识别 我得到了上面的错误,不知道我需要做什么来纠正它。我正在运行一个查询,将CKAssets返回到集合视图中以显示图片。我希望两个文本字段匹配,以及它们何时匹配关联的图像以填充视图。有人有什么建议吗Ios Cloudkit,无法识别的选择器,ios,swift,uicollectionview,cloudkit,Ios,Swift,Uicollectionview,Cloudkit,[CKRecord stringForKey:]:发送到实例0x17412ece0的选择器无法识别 我得到了上面的错误,不知道我需要做什么来纠正它。我正在运行一个查询,将CKAssets返回到集合视图中以显示图片。我希望两个文本字段匹配,以及它们何时匹配关联的图像以填充视图。有人有什么建议吗 @IBOutlet var myCollectionView: UICollectionView! let reuseIdentifier = "MyCell" var matchedSelfie
@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
}
错误说明了这一点。自拍键
不存在
您必须检查密钥是否确实存在。如果密钥存在,您可以尝试使用objectForKey
:
let aselfie = record.objectForKey("selfie") as String
好的,明白了。错误出现在上一个视图中。它没有将记录写入云工具包。非常感谢。