Reputation: 1053
I am trying to pass data from one view controller to another using this method:
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if segue.identifier == "toSecondViewController" {
let secondViewController = segue.destination as! SecondViewController
SecondViewController.username = "Austin"
}
}
However, I'm getting the error
Instance member 'username' cannot be used on type 'SecondViewController'
the variable username
has been defined in SecondViewController
and the segue is indeed named toSecondViewController
. What might be causing this error?
Upvotes: 1
Views: 42
Reputation: 3428
This happens to me all the time.
if segue.identifier == "toSecondViewController" {
let secondViewController = segue.destination as! SecondViewController
SecondViewController.username = "Austin"
}
Notice how SecondViewController.username = "Austin"
has a capital S.. it should be lower case.
You declare a variable let secondViewController as! SecondViewController
but then you try to set .userName on SecondViewController, capital S
You should set .userName on the variable secondViewController
. Lowercase s, which is what you intended.
Upvotes: 1