Xcode 6.2 - Expected type after 'as'
Asked Answered
N

2

12

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

Noodlehead answered 13/3, 2015 at 21:13 Comment(3)
Please copy and paste relevant code instead of imagesBrittaneybrittani
Updated my question, sorry..i am newbieNoodlehead
The solution for me was downgrading some dependencies to remove the '!'Irritate
S
22

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.)

Setaceous answered 13/3, 2015 at 21:57 Comment(0)
C
5

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

Cacka answered 13/3, 2015 at 21:24 Comment(3)
I using just downloading it from github to ready to import to my project. Should i remove them manually? It show nearly 50++ error inside it.Noodlehead
If you need to work in Xcode 6.2 your only choice is to remove them. Since as! is not a valid combination in Swift 1.1 (the actual Swift version that is shipped with Xcode 6.2), you can mass replace it with asTimeous
Excuse-me, it's Xcode 6.3 that uses Swift 1.2. In Swift 1.2, you have 2 possibilities to use as with or without !. Swift 1.2 separate the use of ! developer.apple.com/swift/blogCacka

© 2022 - 2024 — McMap. All rights reserved.