Title is sub-optimal, suggestions welcome
Ran into a little trouble with Bool
and numeric values. I want to determine if an AnyObject
(from a JSON) is a Bool
or a number.
So I need a test that will only succeed if the inserted type was truly a Bool
or a number. Now it automatically converts and all statements are true.
let some : AnyObject = 1
if some is Bool {
print("is Bool", some as! Bool)
}
if some is Int {
print("is Int", some as! Int)
}
let some2 : AnyObject = false
if some2 is Bool {
print("is Bool", some2 as! Bool)
}
if some2 is Int {
print("is Int", some2 as! Int)
}
let some3 : AnyObject = 1.1
if some3 is Bool {
print("is Bool", some3 as! Bool)
}
if some3 is Int {
print("is Int", some3 as! Int)
}