当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Error with ckrecord name

问题描述:

I am getting a sigabrt thread 1 error: "Terminating app due to uncaught exception 'CKException', reason: 'recordName can not be empty'

*** First throw call stack:" and can't figure out where I'm going wrong.

class SweetsTableViewController: UITableViewController {

var sweets = [CKRecord]()

override func viewDidLoad()

{

super.viewDidLoad()

loadData()

}

func loadData()

{

sweets = [CKRecord]()

let publicData = CKContainer.defaultContainer().publicCloudDatabase

let query = CKQuery(recordType: "Beam", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray:nil))

query.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]

publicData.performQuery(query, inZoneWithID: nil) { (results: [CKRecord]?, error: NSError?) -> Void in

if let sweets = results

{

self.sweets = sweets

dispatch_async(dispatch_get_main_queue(), { () -> Void in

self.tableView.reloadData()

})

}

}

}

@IBAction func sendSweet(sender: AnyObject)

{

let alert = UIAlertController(title: "New Beam", message: "Type a Beam", preferredStyle: .Alert)

alert.addTextFieldWithConfigurationHandler { (textField: UITextField) in

textField.placeholder = "Your Beam"

}

alert.addAction(UIAlertAction(title: "Send", style: .Default, handler: {(action: UIAlertAction) -> Void in

let textField = alert.textFields!.first!

if textField.text != ""

{

let newBeam = CKRecord(recordType: "Beam")

newBeam["content"] = textField.text

let publicData = CKContainer.defaultContainer().publicCloudDatabase

publicData.saveRecord(newBeam, completionHandler: {(record:CKRecord?, error: NSError?) -> Void in

if error == nil

{

print("Beam saved")

}

})

}

}))

alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))

self.presentViewController(alert, animated: true, completion: nil)

}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)

if sweets.count == 0

{

return cell

}

let sweet = sweets[indexPath.row]

if let sweetContent = sweet["content"] as? String

{

let dateFormat = NSDateFormatter()

dateFormat.dateFormat = "MM/dd/yyyy"

let dateString = dateFormat.stringFromDate(sweet.creationDate!)

cell.textLabel?.text = sweetContent

cell.detailTextLabel?.text = dateString

}

return cell

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: