Simple example that I don't understand why is not working:
let f: Any = ["": 1]
if let f = f as? [String: Any] {
"" // never enters
}
I'm trying to get this around my head, but don't understand why does this not work. I'm trying to work with numbers and bool, so won't to use anyobject due to the cast to nsnumber that both are redirected to and since I'm writing it in pure-swift for a school project I am not allowed to use that cast (JSON).
UPDATE
The project must handle JSON like SwiftyJSON library in GitHub, but without using AnyObject, ObjC or the NSNumber class.
Update 2
public struct JSON {
public enum Type: Int {
case Bool = 0
case Number
case String
case Array
case Dictionary
case Null
}
var value: Any?
var type: Type {
switch value {
case let value as Bool: return .Bool
case let value as Number: return .Number
case let value as String: return .String
case let value as [Any]: return .Array
case let value as [String: Any]: return .Dictionary
default: return .Null
}
}
init(_ value: Any?) {
self.value = value
}
}
let json = JSON([2])
This example falls in Null case