[英]Swift - 'AnyObject!' is not convertible to 'ViewController'; did you mean to use 'as!' to force downcast?
I just updated my xcode from 6.2 to 6.3.1. 我刚刚将我的xcode从6.2更新到6.3.1。 The problem is I got a lot of this error message inside my project. 问题是我在项目中收到了很多错误信息。
/Users/MNurdin/Documents/iOS/xxxxx/Controllers/Profile/DirectoryTableViewController.swift:31:98: 'AnyObject!' /Users/MNurdin/Documents/iOS/xxxxx/Controllers/Profile/DirectoryTableViewController.swift:31:98:'AnyObject!' is not convertible to 'ViewController'; 不能转换为'ViewController'; did you mean to use 'as!' 你的意思是用'as!' to force downcast? 迫使低垂?
One of my code that affected with this error message. 我的一个代码受此错误消息影响。
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let viewController = storyBoard.instantiateViewControllerWithIdentifier("LoginView") as! ViewController
self.presentViewController(viewController, animated:true, completion:nil)
After updating to Xcode 6.3, you are now using Swift 1.2 更新到Xcode 6.3后,您现在使用的是Swift 1.2
Prior to Swift 1.2, as
was also used for forced conversion. 在Swift 1.2之前, as
也用于强制转换。
Swift 1.2 now represents forced conversions with as!
Swift 1.2现在表示强制转换为as!
to make it clear that the conversion may fail if you attempt to downcast to a type that doesn't actually represent the value's type. 如果您尝试向下转换为实际上不代表值类型的类型,则表明转换可能会失败。
So you have to use as!
所以你必须使用as!
instead of as
而不是as
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.