This is not valid (bad expression)
if !(let nsDictionaryObject = swiftObject as? NSDictionary) { "Error could not make NSDictionary in \(self)" return }
Is it possible to check for negation of Option Chain expression on 1 line?
In Swift 2.0, you can use
guard let nsDictionaryObject = swiftObject as? NSDictionary else { "Error could not make NSDictionary in \(self)" return }
This will also bind nsDictionaryObject to scope outside of the guard statement.
nsDictionaryObject
If you are using swift 1.2 you can do it like this:
if let nsDictionaryObject = swiftObject as? NSDictionary{} else { //your code }
In Swift 1, you can for example use a branch else or check out the result nil .
else
nil
var swiftObject: AnyObject = "" if let _ = swiftObject as? NSDictionary { } else { println("error") } if swiftObject as? NSDictionary == nil { println("error") }