Answer the question
In order to leave comments, you need to log in
Why can't Any be cast to Int?
Hello!
I don't quite understand why I can't cast Any directly to Int?
let str: Any = "12"
print( str as! Int )
let str: Any = "12"
print( str as! String )
let str: Any = "12"
print( Int(str as! String) ?? 0)
Answer the question
In order to leave comments, you need to log in
because these types do not have the same protocols:
error: protocol type 'Any' cannot conform to 'BinaryInteger' because only concrete types can conform to protocols
print( Int(str) )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question