how to make Completion Handlers and use it in Swift

前端之家收集整理的这篇文章主要介绍了how to make Completion Handlers and use it in Swift前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Example 1:
no input parameters,just has return like String type

func method1( completion: (result: String) -> Void) {
//some code
completion(“This is method1 result”)
}
Usage:
method1() {
(result: String) in
print(“got back: (result)”)
}

Example 2:
has input parameters,AND has return like String type

func method2(input: String,completion: (result: String) -> Void) {
//some code
completion(“This is method2 result”)
}

Usage: method2(“input parameter value”) { (result: String) in print(“got back: (result)”) }

原文链接:https://www.f2er.com/swift/322922.html

猜你在找的Swift相关文章