-1

So I'm working on a savings app using a table view controller. I ran into an error, and I couldn't find a fix.

if let sourceViewController = sender.source as? SavingsTableViewController, let saving = sourceViewController.savings {
  let newIndexPath = IndexPath(row: saving.count, section: 0)
  saving.append(saving)
  SavingsTableViewController.insertRows(at: [newIndexPath], with: .automatic)
}

The error shows up as Initializer for conditional binding must have Optional type, not '[Savings]'

Thanks for the help!

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
Evan
  • 125
  • 7

1 Answers1

1

Change

if let sourceViewController = sender.source as? SavingsTableViewController, let saving = sourceViewController.savings {
    let newIndexPath = IndexPath(row: saving.count, section: 0)
    // and so on

To

if let sourceViewController = sender.source as? SavingsTableViewController {
    let saving = sourceViewController.savings
    let newIndexPath = IndexPath(row: saving.count, section: 0)
    // and so on

(Your code still won’t work as intended, but this will get you past the compile error.)

matt
  • 515,959
  • 87
  • 875
  • 1,141