0

I am trying to segue to a new viewcontroller in swift 3. I am also trying to send an array to the new viewcontroller, I am doing this programmatically as well. here is the code for my segue:

performSegue(withIdentifier: "AlbumSegue", sender:self) {
            let destinationVC = segue.destination as!  DestinationViewController
            destinationVC.recievedArray = selectedAlbumArray

The error I get is "Extra Argument 'Sender' in Call"

So if I take out the sender part and my code becomes:

performSegue(withIdentifier: "AlbumSegue") {
            let destinationVC = segue.destination as! DestinationViewController
            destinationVC.recievedArray = selectedAlbumArray
            }

I then get an error saying "use of unresolved Identifier 'segue'"

But I've found code examples like this:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let destinationVC = segue.destination as! DestinationViewController
    destinationVC.receivedString = stringToPass
    }
}

Basically both of these problems are in TEMPLATES for doing this so I don't know why either errors are occurring because according to answers on StackOverflow these aren't errors at all.

Coder Boy
  • 3
  • 5
  • The code example is prepare() not preformSegue(), so those are different functions for one thing. – Daniel Legler Mar 22 '17 at 17:02
  • This question has been asked so many times: http://stackoverflow.com/questions/29734954/how-do-you-share-data-between-view-controllers-and-other-objects-in-swift – Daniel Legler Mar 22 '17 at 17:03
  • @DanielLegler I see, could you point me in the way of a performeSegue() tutorial instead of a prepare that can pass a variable? or is it only possible to pass an array with prepare()? – Coder Boy Mar 22 '17 at 17:22
  • prepare(forSegue:) gets called right before a segue happens. So when you call performSegue it will first execute whatever is in prepare(forSegue:) – Daniel Legler Mar 22 '17 at 17:23
  • I see so its a two part thing, and im basically meshing them into one, sorry for the repetitive question, but that answers why I couldn't find anything on it lol I appreciate your patience – Coder Boy Mar 22 '17 at 17:30

0 Answers0