In the communicator class, the method that the web service computes will be defined like this, depending on the type of object you want to return
func performRequest(serviceName: NSString, methodName: NSString,paramaters:NSDictionary, successblock: (String)->(), failureBlock: () -> ()) { if(callSuccess) { successblock("Success") } else { failureBlock() }
We determine the types of success and failure blocks, since their function signatures in the above case are defined as a method that takes a string as an input parameter and returns nothing, so we can then call successBlock, passing in a string. The failure block is defined above as a block that takes no parameters and returns nothing.
To call this method
func callWebService(serviceName: NSString, method: NSString and parameters: NSDictionary, showLoader: Bool, completionBlockSuccess:(String) -> (), completionBlockFailiure:() -> ()) { if (showLoader) { // show loader } performRequest(serviceName: serviceName, methodName: method, parameters, successBlock:completionBlockSuccess, failureBlock: completionBlockFailiure) }
Finally, to call it
Communicator.sharedInstance().callWebService(serviceName: WS_LOGIN , method: POST_METHOD and parameters: params, showLoader: true, completionBlockSuccess:{ returnedString in
In the completion block, we define the variable returnString so that we can manipulate this input parameter (in the example above, this will be the string "Success"). I assume that your data does not just return a string, although you may have to play around with it, depending on what your service returns.
Also here I tried to match your method signatures using NSString and NSDictionary, although depending on your needs, more suitable equivalents to String and [String: AnyObject] may be more appropriate.