swift - 作为的意思!在 Swift 1.2 - Xcode 6.3 beta 中

标签 swift

我只是尝试 XCode 6.3 beta 和 Swift 1.2

这里的as!是什么意思?

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

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

    }

最佳答案

这意味着,如果segue.destinationViewController是一个SignUpViewController,它会将其转换为SignUpViewController,否则它将产生一个运行时错误。 但如果您使用 as?,在这种情况下,如果 segue.destinationViewControllerNOT 一个 SignUpViewController,那么它将是只是零,没有运行时错误。

关于swift - 作为的意思!在 Swift 1.2 - Xcode 6.3 beta 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28454961/

相关文章:

xcode - 如何在 Swift 中的文件之间共享常量和变量

swift - 比较 Int32 的谓词

ios - 当我在 Parse 中创建任何对象时,createdAt 属性不是正确的创建时间。

iOS 在 UIImageView 顶部淡化为黑色

xcode - 使用 Swift 为 OS X 应用程序动画 View 移动

ios - 在 iOS Swift 上弃用后 Twitter.sharedInstance().session()?.userName 的替代方案

swift - 为什么在按下另一个按钮时不会在 uibutton 上触发 touch-up inside 事件?

ios - 在 iOS 设备上访问应用内购买

ios - 应用程序无法在第二个模拟器上运行?

ios - UIButton 不能横向工作