I want to return some values โโafter the completion of a long-term operation. But also, I would like to separate the logic and gui.
For example; I have two classes
- SomeServices.swift, which has a method called getDataFromService ...
- MyTableViewController.swift, which will display the result from "getDataFromService"
So, earlier in Objective-C, I just added a method to SomeServices, like this:
(void)getDataFromService:(void (^)(NSArray *, NSError *))completionBlock{ ...... }
In this method, I just called completionBlock(myData, myError) to return my values โโto tableviewcontroller.
What will be the equivalent closure I have to define in SomeServices.swift and how will it be called in MyTableViewController?
I know how to cause simple closures like this:
....({ responseData, error in if(!error){
But I have no idea how to define a closure with the equivalent of Block completion.
Any help would be appreciated
ios8 swift
user1011394
source share