Answers for "handler swift 4"

3

swift how to add a completion block to a function

Simple Swift 4.0 example:

func method(arg: Bool, completion: (Bool) -> ()) {
    print("First line of code executed")
    // do stuff here to determine what you want to "send back".
    // we are just sending the Boolean value that was sent in "back"
    completion(arg)
}
How to use it:

method(arg: true, completion: { (success) -> Void in
    print("Second line of code executed")
    if success { // this will be equal to whatever value is set in this method call
          print("true")
    } else {
         print("false")
    }
})
Posted by: Guest on January-13-2020
0

swift completion handler

func thisNeedsToFinishBeforeWeCanDoTheNextStep(completion: (String) -> ()) {    
    let stringToPassOutOfTheCompletionHandler = "The quick brown fox"    
    completion(stringToPassOutOfTheCompletionHandler)
}
Posted by: Guest on April-17-2020

Code answers related to "handler swift 4"

Code answers related to "Swift"

Browse Popular Code Answers by Language