Deepak Thakur
Deepak Thakur

Reputation: 51

How we write own function in swift with completionHandler

in objective c i write a method

-(void)loginApi:(NSMutableDictionary*)dict completion:(void(^)(NSDictionary *json,BOOL sucess))completion {

how we write same method

Upvotes: 1

Views: 582

Answers (3)

Mike.R
Mike.R

Reputation: 2948

Although Previous answers will work I would suggest to alias it instead of typing the declaration every time (it also concern Objective c).

 typealias CompletionHandlerType = (error:NSError ,response:AnyObject?) -> Void

Upvotes: 0

simplytunde
simplytunde

Reputation: 197

    func loginApi(dict: NSMutableDictionary, completion: (json:NSDictionary,success: Bool) -> Void){
    //Do whatever you want to do here
    completion(json: dict, success: true) //This is just an example of how you can call
    }

Give this a try. I think it should work. If not,let me know.

Upvotes: 1

Mou
Mou

Reputation: 2147

func loginApi(completion : (json: [Dictionary<String, String>, success: Bool]) -> [Dictionary<String Int>]) {
    ...
    completion(...)
}

Upvotes: 0

Related Questions