Emily Emily - 1 year ago 62
Swift Question

readWithCallback function not working in swift 3

Before the swift update(in swift 2) my code was like the following and it worked successfully with no errors.

(list: Array<AnyObject>!, error: MSOrcError!) -> Void in

But after the swift update (in Swift 3) I get errors in the previous code, so I changed it to the below code. It has no errors but when I run the app it gets crashes and terminates. When I remove the last line I get an error saying:

Cannot convert value of type 'Any?' to expected argument type
'(([Any]?, MSOrcError?) -> Void)!'

client.me.events.read(callback: Any?{
(list: Array<AnyObject>!, error: MSOrcError!) -> Void in
} as! (([Any]?, MSOrcError?) -> Void)! )

How do I solve this error?

Answer Source

The error message says that the expected argument type is (([Any]?, MSOrcError?) -> Void)!. Why don't you follow it?

    client.me.events.read(callback:  {(list: [Any]?, error: MSOrcError?) in

Or simply:

    client.me.events.read {list, error in
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download