Ios UIViewController在XCode 7中不再具有topViewController或ViewController成员

Ios UIViewController在XCode 7中不再具有topViewController或ViewController成员,ios,swift2,xcode7,Ios,Swift2,Xcode7,更新到XCode 7并将我的项目转换为最新的Swift 2语法后,有一个错误我似乎无法修复。我有一个导航控制器的序列,需要将数据传递到堆栈中的top view控制器。到目前为止,以下方法一直有效: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let destinationVC = segue.destinationViewController.viewControllers[0

更新到XCode 7并将我的项目转换为最新的Swift 2语法后,有一个错误我似乎无法修复。我有一个导航控制器的序列,需要将数据传递到堆栈中的top view控制器。到目前为止,以下方法一直有效:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let destinationVC = segue.destinationViewController.viewControllers[0] as! MYViewController
    // OR let destinationVC = segue.destinationViewController.topViewController as! MYViewController
    // ...
}
但现在编译器给出了错误:

类型“UIViewController”的值没有成员“ViewController”
类型为“UIViewController”的值没有成员“topViewController”


我看不到如何访问堆栈上的视图控制器。有什么想法吗?提前谢谢

添加
as!UINavigationController
segue.destinationViewController
之后,以便转换为
UINavigationController
类类型

let destinationVC = (segue.destinationViewController as! UINavigationController).viewControllers[0] as! MYViewController

在Swift 3(代码8)中更新至

或者
ViewController[0]
可以替换为
topViewController

let destinationVC = (segue.destinationViewController as! UINavigationController).topViewController as! MYViewController
let dvc = (segue.destination as! UINavigationController).viewControllers[0] as! MyViewController