Reputation: 523
I need to initialize a Dictionary on Swift for an app that works on iOS 7+. On iOS 8 everything works fine, but on iOS 7 the dictionary is always empty.
I tried
var parameters = Dictionary<String, String>()
parameters["grant_type"] = "password"
and also
let parameters = ["grant_type" : "password"]
On both cases the result is
Printing description of parameters:
([String : String!]) parameters = {}
It's a Swift bug or I did something wrong here? FYI: I'm using Xcode 6.1 (Swift 1.1)
Upvotes: 0
Views: 239
Reputation: 1129
Actually, swift dictionaries seem to work, but debugging will show empty values. The answer is, to debug, cast from Swift dictionary to NSDictionary
print(swiftDictionary as NSDictionary)
Original
Swift Dictionaries do not work in iOS 7 for whatever reason. he workaround is to use NSDictionary.
Upvotes: 2