Josh O'Connor Josh O'Connor - 1 month ago 26
iOS Question

Updating to Swift 3.0: Contextual type 'AnyObject' cannot be used with dictionary literal

Im updating my codebase to Swift 3.0, and I cannot figure out how to fix the error I am generating when migrating: "Contextual type 'AnyObject' cannot be used with dictionary literal". Any help would be greatly appreciated.

typealias JSONDictionary = Dictionary<String, AnyObject>

func infoDict() -> JSONDictionary {
return ["users" :
//the following line generates the error "Contextual type 'AnyObject' cannot be used with dictionary literal"
["add" : Array(self.addUserIDs), "del" : Array(self.removeUserIDs)],
"groups" :
["add" : Array(self.addCircleIDs), "del" : Array(self.removeCircleIDs)],
"friends" : friends,
"type" : 1
]
}

Answer

AnyObject has been changed to Any in Swift 3

typealias JSONDictionary = Dictionary<String, Any>
Comments