简体   繁体   English

斯威夫特 - 'AnyObject!' 不能转换为'ViewController'; 你的意思是用'as!' 迫使低垂?

[英]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.

相关问题 “ ValidationError”不能转换为“ Error”;您是要使用“ as!”吗? 强迫垂头丧气? - 'ValidationError' is not convertible to 'Error';did you mean to use 'as!' to force downcast? 'NSString的!' 不能转换为'String'; 您是要使用“ as!”吗? 强迫垂头丧气? - 'NSString!' is not convertible to 'String'; did you mean to use 'as!' to force downcast? Swift:在“ ViewController”类型上使用实例成员; 您是不是要使用'ViewController'类型的值代替 - Swift: Use of instance member on type 'ViewController'; did you mean to use a value of type 'ViewController' instead “ NSData”不能隐式转换为“ Data”; 您是要使用“ as”进行显式转换吗? - 'NSData' is not implicitly convertible to 'Data'; did you mean to use 'as' to explicitly convert? 未包装的可选类型“ AnyObject?”的值不是您要使用的! 要么? - Value of optional Type “AnyObject?” not unwrapped did you mean to use ! or? 在Swift中将anyObject转换为String - Downcast anyObject to String in Swift Swift 2:AnyObject? 不能转换为NSString - Swift 2: AnyObject? is not convertible to NSString Swift:'()'不能转换为'[String:AnyObject]' - Swift: '()' is not convertible to '[String : AnyObject]' 从“UIViewController?”向下转型? 'UIViewController' 只解开可选项; 你的意思是使用“!”? - Downcast from 'UIViewController?' to 'UIViewController' only unwraps optionals; did you mean to use '!'? 是否从“ CLLocation”下调? 到“ CLLocation”仅解开可选部分; 您是要使用'!'吗? - Downcast from 'CLLocation?' to 'CLLocation' only unwraps optionals; did you mean to use '!'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM