【问题标题】:Crash: fatal error: unexpectedly found nil while unwrapping an Optional value崩溃:致命错误:在展开可选值时意外发现 nil
【发布时间】:2015-09-19 18:56:36
【问题描述】:

我不知道为什么会出现此错误:fatal error: unexpectedly found nil while unwrapping an Optional value

这是我的ViewController 代码:

class TableViewController: UITableViewController {


var objects = [Play]()


override func viewDidLoad() {
    super.viewDidLoad()

    let container = CKContainer.defaultContainer()
    let publicData = container.publicCloudDatabase

    let query = CKQuery(recordType: "Play", predicate: NSPredicate(format: "TRUEPREDICATE", argumentArray: nil))
    publicData.performQuery(query, inZoneWithID: nil) { results, error in
        if error == nil { // There is no error
            for play in results! {
                let newPlay= Play()
                newPlay.title = play["Title"] as! String
                newPlay.description = play["Description"] as! String

                NSLog("Title %@", newPlay.title);

                self.objects.append(newPlay)

                dispatch_async(dispatch_get_main_queue(), { () -> Void in
                    self.tableView.reloadData()
            })
            }
        }
        else {
            print(error)
        }
    }

}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return objects.count
}


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)

    let object = objects[indexPath.row]

    if let label = cell.textLabel{
        label.text = object.title
    }

    return cell
}

我的情节提要似乎也连接了所有内容。

有什么想法吗?将根据需要发布任何额外的代码,谢谢!

【问题讨论】:

  • 哪个对象是nil
  • 他们都不知何故

标签: swift uitableview cloudkit


【解决方案1】:

我从 CloudKit 中提取了错误的密钥。感谢您的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-26
    • 2016-02-29
    • 2020-09-19
    • 2016-01-08
    相关资源
    最近更新 更多