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")
}
})
Also in Swift:
- register for remote notifications swift
- swift list
- swift sort array
- Split a String into an array in Swift
- swift remove tableview cell
- give background color swiftui
- time formats swift
- swift check if regex is in string
- how to swift pie chart quartzcore framework
- fnb swift code
- swift ns_enum generic name
- swift temporary directory
- store bool value in nsuserdefaults swift
- swift uitextfield only numbers keyboard lock programmatically
- swift how to add a completion block to a function
- limit log file size swift
- deselect all cell in collectionview
- swift add horizontal line uiview programmatically
- enum from raw value swift
- swift dispatch after
- sheet swiftui
- swift close app
- swift wait 5 seconds
- how to show notification icon on tabbar item swift