I have a problem trying to create a JSON object. Everything is fine until I try to create a second level element with nil values:
var json = [String: AnyObject]()
json["id"] = 1234567
let secondLevel : [String: AnyObject] = ["i1": 12, "i2": "not nil"]
json["secondLevel"] = secondLevel
This is fine, but if I try:
let secondLevel : [String: AnyObject?] = ["i1": 12, "i2": nil]
json["secondLevel"] = secondLevel
I got the following error:
cannot assign a value of type '[String : AnyObject?]' to a value of type 'AnyObject?'
What does it means? Isn't a [String:AnyObject?]
of AnyObject
type?
What could I do to avoid this error?