In swift i want send NSError in a method completion block like in objective c.
Asked
Active
Viewed 126 times
-2
-
1Your question is misleading. Do you want answer in `Swift` or `Objective-C`? Your question title says one and your question detail says another. – nayem Aug 19 '17 at 17:49
-
`title says one and [question] says another` tagged as both. (I'd probably not tag [objective-c], make [swift] the 1st tag, not mention swift in the title and ogle the result to decide whether to (fully) hyphenate *Objective-C-like*.) (Please capitalise as best you can (the personal pronoun *I*, for one). (Use a spelling checker.) In the title, the indefinite article `a` precedes something pronounced starting with a vowel: I'd use *an*.) – greybeard Aug 19 '17 at 18:00
1 Answers
1
Closure is same as objective c block. you can try this:
func myFunc(withCompletionHandler completionHandler:((NSError?) -> Swift.Void)?){
var error:NSError? = nil
//DO YOUR TASK AND ASSAIGN ERROR TO var error
completionHandler?(error)
}

Andy Ibanez
- 12,104
- 9
- 65
- 100

Torongo
- 1,021
- 1
- 7
- 14