Daniel Gomez Rico
Daniel Gomez Rico

Reputation: 15945

Meaning of as! in Swift 1.2 - Xcode 6.3 beta

I'm just trying XCode 6.3 beta and Swift 1.2

What is the meaning of the as! here?

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == signUpViewId {
            var signUpView = segue.destinationViewController as! SignUpViewController
        }

    }

Upvotes: 2

Views: 213

Answers (1)

Dániel Nagy
Dániel Nagy

Reputation: 12045

It means, that if segue.destinationViewController is a SignUpViewController, it will cast it to a SignUpViewController, otherwise it will produce a runtime error. But if you would use as?, that case if segue.destinationViewController is NOT a SignUpViewController, it would be just nil, without runtime error.

Upvotes: 3

Related Questions