swift - 崩溃: fatal error: unexpectedly found nil while unwrapping an Optional value

标签 swift uitableview cloudkit

我不明白为什么会收到此错误: fatal error :在解包可选值时意外发现 nil

这是我的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
}

一切似乎也都连接在我的 Storyboard中。

enter image description here

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

最佳答案

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

关于swift - 崩溃: fatal error: unexpectedly found nil while unwrapping an Optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32672059/

相关文章:

ios - 什么时候调用 cellForRowAtIndexPath 方法?

ios - 表格 View 用最后一个 xml 条目填充所有单元格 iphone

ios - 从 iOS 14 或 14.0.1 开始 WiFi 可以工作,但 LTE 不能

ios - CloudKit,无法修改某些记录 - 未找到区域

CloudKit错误: Couldn't get a PCS object to unwrap encrypted data for field encryptedPublicSharingKey

ios - 在标签栏应用程序上推送新标签

使用 CAShapeLayer() 和 UIBezierPath 快速绘制和调整圆

ios - 将 View 的 NSLayoutConstraint 设置为右上角

swift - 在 swift 5 中使用 UTF-8 解码字符串

ios - UITableView - 点击更改单元格颜色