According to Swift 3 documentation, NSNumber is bridged to Swift native types such as Int, Float, Double,...But when I try using a native type in Dictionary I get compilation errors that get fixed upon using NSNumber, why is that? Here is my code :
var dictionary:[String : AnyObject] = [:]
dictionary["key"] = Float(1000)
and the compiler gives error "Can not assign value of type Float to AnyObject". If I write the code as follows, there are no issues as NSNumber is actually an object type.
dictionary["key"] = NSNumber(value:Float(1000))
Swift compiler also prompts to correct the code as
dictionary["key"] = Float(1000) as AnyObject
but I am not sure if it is correct thing to do or not. If indeed there is a bridging between NSNumber and native types(Int, Float, etc.), why is compiler forcing to typecast to AnyObject?