条件绑定错误中的绑定值

时间:2014-09-09 23:50:21

标签: swift

我刚刚更新了Xcode 6的GM,我一直在修复出现的错误。但是我遇到了一个特定的错误。

这是我的代码:

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if (editingStyle == UITableViewCellEditingStyle.Delete) {
        if let tv=tableView {
            if tableView == self.searchDisplayController?.searchResultsTableView {
                UITableViewCellEditingStyle.None
            } else {
            var valueToRemove: AnyObject! = unformatted.objectAtIndex(indexPath.row)
            //println(valueToRemove)

            if images.objectAtIndex(indexPath.row) as NSObject == 0 {
                totalSpendingsCounter = totalSpendingsCounter - Double(valueToRemove as NSNumber)
                NSUserDefaults.standardUserDefaults().setDouble(totalSpendingsCounter, forKey: "spendingsCounter")
            } else if images.objectAtIndex(indexPath.row) as NSObject == 1 {
                totalCreditCounter = totalCreditCounter - Double(valueToRemove as NSNumber)
                NSUserDefaults.standardUserDefaults().setDouble(totalCreditCounter, forKey: "creditCounter")
            }

            currencyDouble = NSUserDefaults.standardUserDefaults().doubleForKey("currencyCounter")
            currentBudgetCalculation = currencyDouble + totalCreditCounter - totalSpendingsCounter

            newTransactionEntered = true

            var formatter = NSNumberFormatter()
            formatter.numberStyle = .CurrencyStyle
            formatter.locale = NSLocale.currentLocale() // This is the default
            var formattedNumberCurrent = formatter.stringFromNumber(currentBudgetCalculation)

            var defaults = NSUserDefaults(suiteName: "group.AffordIt")
            defaults.setObject(formattedNumberCurrent, forKey: "currentBudgetWidget")
            defaults.setObject(newTransactionEntered, forKey: "new")

            values.removeObjectAtIndex(indexPath.row)
            images.removeObjectAtIndex(indexPath.row)
            names.removeObjectAtIndex(indexPath.row)
            dates.removeObjectAtIndex(indexPath.row)
            unformatted.removeObjectAtIndex(indexPath.row)

            NSUserDefaults.standardUserDefaults().setObject(names, forKey: "names")
            NSUserDefaults.standardUserDefaults().setObject(values, forKey: "values")
            NSUserDefaults.standardUserDefaults().setObject(dates, forKey: "dates")
            NSUserDefaults.standardUserDefaults().setObject(unformatted, forKey: "unformatted")
            NSUserDefaults.standardUserDefaults().setObject(images, forKey: "images")

            tv.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
            }
        }
    }
}

我收到错误:

Bound value in a conditional binding must be of Optional type.

在这一行:

if let tv=tableView {

我对编程很陌生,所以我确定有一个明显的解决办法,但在做了一些研究和尝试之后我无法识别它。

1 个答案:

答案 0 :(得分:2)

自Xcode 6 beta 7起,tableView:commitEditingStyle:forRowAtIndexPath:的UITableView参数不再是可选项。因此,您无法尝试使用可选绑定将其解包。

您必须更改代码才能解决此问题。现在,我想你的可选绑定不再是必要的......