A safer and more direct approach is a conditional listing or even better protocol-based listing, consider the following:
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { if let vc = segue.destinationViewController as? FirstViewController { vc.SelectedBundesland.text = "Test" } else { print("Some other controller! \(segue.destinationViewController)") } }
It certainly works. But if you have several segues and multiple viewController, this can be a big problem for changing information and data around.
Consider the protocol approach:
protocol BundeslandProtocol { var SelectedBundesland: String {get set} } override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { if var vc = segue.destinationViewController as? BundeslandProtocol { vc.SelectedBundesland.text = "Test" } }
To do the above work, you just need to declare your UIViewController to match the specified protocol:
class AwesomeViewController: UIViewController, BundeslandProtocol { .... }
Over time, you will be able to rename your classes, change them, replace and expand your project, and you will not have to worry about changing the links if the protocol retains its purpose.
It is not easy to say where your code is broken: this usually happens when you forget to specify the name of your class (FirstViewController in your case) in the storyboard, for the controller for which segue is executed, see screenshot, it has instead of the standard class UIViewController.

source share