0
所以這是我的代碼,允許警報和寫入警報內的文本保存在雲中。我實際上是遵循一個教程https://www.youtube.com/watch?v=XQ3nLV2778U 即時消息得到2我的一些代碼錯誤消息!我的代碼有什麼問題(雲工具包)
- 錯誤:任何對象是不相同的CKRecords(位於self.post =交)
- 錯誤:CKRecords不具有命名標構件(位於newPost [ 「內容」]
我寫的代碼的確切方式的傢伙在本教程做了,除了我有錯誤訊息,他不!我該如何解決這些?
var posts = [CKRecord]()
override func viewDidLoad() {
super.viewDidLoad()
}
func loadData() {
posts = [CKRecord]()
let publicData = CKContainer.defaultContainer().publicCloudDatabase
let query = CKQuery(recordType: "Post", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil))
publicData.performQuery(query, inZoneWithID: nil) { (CKRecord, NSError) -> Void in
if let posts = CKRecord{
self.posts = posts //Error "Any Object is not Identical to CKRecords"
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.tableView.reloadData()
})
}
}
}
@IBAction func createPost(sender: AnyObject) {
let alert = UIAlertController(title: "New Post", message: "Enter New Post", preferredStyle: .Alert)
alert.addTextFieldWithConfigurationHandler { (textField:UITextField!) -> Void in
textField.placeholder = "Your Post"
}
alert.addAction(UIAlertAction(title: "Post", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> Void in
let textField: AnyObject = alert.textFields!.first!
if textField.textLabel??.text != "" {
let newPost = CKRecord(recordType: "Post")
newPost["content"] = textField.textLabel??.text //ERROR "CKRecord does not have a member named subscript"
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(newPost, completionHandler: { (record: CKRecord?, error: NSError?) -> Void in
if error == nil {
print("Post Saved")
}
})
}
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)