Swift 2 to 3 Does jsonObject migration produce a "Any" not expected context type of result "AnyObject"?

I am trying to convert the following code from this library ( https://github.com/dankogai/swift-json ) to Swift 3 compatibility code.

I am stuck on this line though.

obj = try JSONSerialization.jsonObject( 

The error I get: jsonObject creates "Any" and not the expected type of the context result "AnyObject?"

The code before I try to convert to swift 3 in its full context is below.

 public convenience init(data:NSData) { var err:NSError? var obj:AnyObject? do { obj = try NSJSONSerialization.JSONObjectWithData( data, options:[]) } catch let error as NSError { err = error obj = nil } self.init(err != nil ? err! : obj!) } 
+8
json ios10 swift swift2 swift3
source share
1 answer

In Swift 3 id types are now imported as Any , not AnyObject . You can either change the obj type to Any , or apply it to AnyObject .

+13
source share

All Articles