0

Since Apple decided to change error handling to a much more circuitous system, I'm having trouble updating a line of code in Xcode 7 and am getting an error I'm not familiar with.

I receive an error of: Argument type 'AnyObject.Protocol' does not conform to expected type 'AnyObject'

Here's my old code which used to work:

request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err)

And my current code which is throwing the above error:

do {
    request.HTTPBody = try NSJSONSerialization.dataWithJSONObject(obj: AnyObject, options: nil)
} catch let error as NSError {
    print("Could not be completed due to \(error)")
}

1 Answer 1

2

Try this instead:

do {
    let request = try NSJSONSerialization.dataWithJSONObject(params, options: [])
} catch let error as NSError {
    print("Could not be completed due to \(error)")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.