I am searching a key in an Array
of Dictionarys
and I want to convert the result value into an Int
value. This is what I tried.
I don't know your code but this will be helpful for you.
You can get your AnyObject value in this way...
let data :AnyObject = "100"
let score = Int(data as! String)! //Force Unwrap optional value it will be dengerious for nil condition.
print(score)
Or try this way also
let hitCount = "100"
let data :AnyObject = hitCount as AnyObject //sometime Xcode will ask value type
let score = Int(data as? String ?? "") ?? 0
print(score)
let hitCount = "100"
let data :Any = hitCount //Any type Value passing here
let score = Int(data as? String ?? "") ?? 0
print(score)