小编Del*_*nds的帖子

条件绑定:如果让错误 - 条件绑定的初始化程序必须具有可选类型

我试图从我的数据源和以下代码行中删除一行:

if let tv = tableView {
Run Code Online (Sandbox Code Playgroud)

导致以下错误:

条件绑定的初始化程序必须具有Optional类型,而不是UITableView

这是完整的代码:

// Override to support editing the table view.
func tableView(tableView: UITableView, commitEditingStyle editingStyle:UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {

        // Delete the row from the data source

    if let tv = tableView {

            myData.removeAtIndex(indexPath.row)

            tv.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
Run Code Online (Sandbox Code Playgroud)

我该如何纠正以下问题?

 if let tv = tableView {
Run Code Online (Sandbox Code Playgroud)

ios swift optional-binding

107
推荐指数
5
解决办法
14万
查看次数

向上舍入到小数点后两位

如何舍入currentRatio到小数点后两位?

let currentRatio = Double (rxCurrentTextField.text!)! / Double (txCurrentTextField.text!)!
railRatioLabelField.text! = "\(currentRatio)"
Run Code Online (Sandbox Code Playgroud)

double swift

47
推荐指数
8
解决办法
7万
查看次数

标签 统计

swift ×2

double ×1

ios ×1

optional-binding ×1