40

I'm trying to follow along with Apple's Start Developing iOS Apps (Swift) tutorial and have almost completed it. I have had to amend several parts of the tutorial as I'm using Xcode 8 (which I think uses Swift 3 instead of Swift 2). However, I am running into the following compiler error and I don't know why:

Argument labels (forRow:, inSection) do not match any available overloads

in the following function:

@IBAction func unwindToMealList(sender: UIStoryboardSegue) {

    if let sourceViewController = sender.sourceViewController as? MealViewController, meal = sourceViewController.meal {
        // Add a new meal
        let newIndexPath = NSIndexPath(forRow: meals.count, inSection: 0)
        meals.append(meal)
        tableView.insertRows(at: newIndexPath, with: .bottom)
    }

}

I'm guessing that there is a different initialiser for NSIndexPath that's changed in Swift 3 but I can't find it. Am I doing something wrong?

Thanks,

andig
  • 13,378
  • 13
  • 61
  • 98
Garry Pettet
  • 8,096
  • 22
  • 65
  • 103
  • 4
    Sorry but as a new user of Swift and the Apple docs I thought I was doing a good job of researching. It would help if Apple would keep their tutorials up-to-date and bug free... – Garry Pettet Jul 15 '16 at 21:59
  • 3
    This question gets my plus one as neither code completion in Xcode 8, nor Apple's documentation supplied the answer easily. – Lev Landau Oct 14 '16 at 21:55
  • 1
    this is a valid question! – user363349 Oct 17 '16 at 08:34
  • 2
    Agreed with comments so far. It is not true to say that code completion or the docs answer this question (certainly not easily and for a beginner following the tutorial). Perhaps those saying so should check if it's correct before assuming they do. It's a valid question and should not be closed. –  Dec 06 '16 at 20:36
  • "Did you check the docs?" is almost never a valid response to an iOS or macOS question. For many of the APIs, Apple hasn't even written documentation yet. For all practical purposes, Stack Overflow *is* the Apple documentation. Code completion on Xcode is also notoriously bad. – bugloaf Feb 08 '17 at 17:15

1 Answers1

109

NSIndexPath has been changed to IndexPath

try IndexPath(row: Int, section: Int)

API Reference : indexpath

Swift 3.0 Developer Preview

iOSGeek
  • 5,115
  • 9
  • 46
  • 74