Emily Emily - 4 months ago 18
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?


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