Last active
October 9, 2019 12:30
-
-
Save DaisukeNagata/cb9b6c7de171eff3acb60bf4adb9fcbd to your computer and use it in GitHub Desktop.
closureMethod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tx: String? | |
/// クロージャー機能 bindTx引数に文字、もしくはnilを取得します。 | |
let notify = { (_ bindTx: String?) -> String? in return bindTx } | |
/// クロージャーを返却する機能 | |
/// - Parameter bind: Voidを返却 | |
func closureBind(_ bind: @escaping () -> Void) { | |
tx = "test" | |
bind() | |
} | |
/// txの値がnilでなければnotify(クロージャー)を呼びだす | |
func closureMethod() { | |
print(tx ?? "","nil") | |
closureBind { | |
guard tx?.isEmpty ?? false else { | |
let notifyText = notify(tx) | |
print(notifyText ?? "", "notifyText") | |
return | |
} | |
} | |
} | |
closureMethod() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
closureBindメソッドをAPI系のメソッドにすると、closureBind{ nonnil }の中に入る場合にデータを取得した状態になっている。