Xcode 6.2 - 'as' 后的预期类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29042042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 6.2 - Expected type after 'as'
提问by Chris Suen
First time seeing this error, can't i put '!' after 'as' in swift? Or just bug after updating my Xcode to 6.2?
第一次看到这个错误,我不能放'!' 在 swift 中的 'as' 之后?或者只是在将我的 Xcode 更新到 6.2 后出现错误?
let url = notification.userInfo![CallbackNotification.optionsURLKey] as! NSURL
It shows error : Expected type after 'as'
它显示错误:“as”之后的预期类型
P.S: You can try download OAuthSwift from github to test this error. https://github.com/dongri/OAuthSwift
PS:你可以尝试从github下载OAuthSwift来测试这个错误。 https://github.com/dongri/OAuthSwift
回答by matt
The as!
notation was not introduced until Xcode 6.3. You have Xcode 6.2, so you have to say simple as
. Xcode 6.2 does not understand your as!
; that is the cause of the compiler error you are getting.
这个as!
符号直到 Xcode 6.3 才被引入。你有 Xcode 6.2,所以你必须说 simple as
。Xcode 6.2 无法理解您的as!
; 这就是你得到的编译器错误的原因。
(Note that if you take those !
away, then when you eventually switch to Xcode 6.3 you have will have to bring them all back again! It really is best notto change Xcode versions backwards and forwards like this. If your code was written originally with Xcode 6.3, you should staywith Xcode 6.3. The only problem is that in that case you cannot submit an app to the App Store until it goes final; right now it is still in beta.)
(请注意,如果您将它们!
拿走,那么当您最终切换到 Xcode 6.3 时,您将不得不再次将它们全部带回来!最好不要像这样来回更改 Xcode 版本。如果您的代码最初是用Xcode 6.3,您应该继续使用 Xcode 6.3。唯一的问题是,在这种情况下,您无法将应用程序提交到 App Store,直到它成为最终版本;现在它仍处于测试阶段。)
回答by Duyen-Hoa
You don't have to add ! to as to unwrap your optional variable in XCode 6.2
你不必添加!在 XCode 6.2 中解开你的可选变量