Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 6.2 - Expected type after 'as'

First time seeing this error, can't i put '!' after 'as' in swift? Or just bug after updating my Xcode to 6.2?

let url = notification.userInfo![CallbackNotification.optionsURLKey] as! NSURL

It shows error : Expected type after 'as'

P.S: You can try download OAuthSwift from github to test this error. https://github.com/dongri/OAuthSwift

enter image description here

like image 903
Chris Suen Avatar asked Mar 13 '15 21:03

Chris Suen


2 Answers

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.

(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 not to change Xcode versions backwards and forwards like this. If your code was written originally with Xcode 6.3, you should stay with 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.)

like image 189
matt Avatar answered Oct 12 '22 13:10

matt


You don't have to add ! to as to unwrap your optional variable in XCode 6.2

like image 43
Duyen-Hoa Avatar answered Oct 12 '22 11:10

Duyen-Hoa