I am trying to pass an int variable between views in Swift but I'm not sure how to access the other View controller's property.
In Objective C I would do something like this
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
AnsViewController *ansViewController = [storyBoard instantiateViewControllerWithIdentifier:@"ansView"];
ansViewController.num = theNum;
[self presentViewController:ansViewController animated:YES completion:nil];
And in the other viewcontroller.h file I would write this to declare the property to get the data
@property (nonatomic) int num;
Now for Swift I have this
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let ansViewController : UIViewController = storyBoard.instantiateViewControllerWithIdentifier("ansView") as UIViewController
ansViewController.num = theNum;
self.presentViewController(ansViewController, animated:true, completion:nil)
and in the other .swift file for the other view controller I declared num by doing
let num: int
I'm pretty sure that isn't the right way to do it because I get an error on this line
ansViewController.num = theNum;
and it says, "UIViewController does not have a member named num" How would I resolve this error and what have I done wrong?
Thanks