Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Last active October 9, 2019 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/cb9b6c7de171eff3acb60bf4adb9fcbd to your computer and use it in GitHub Desktop.
Save DaisukeNagata/cb9b6c7de171eff3acb60bf4adb9fcbd to your computer and use it in GitHub Desktop.
closureMethod
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()
@DaisukeNagata
Copy link
Author

closureBindメソッドをAPI系のメソッドにすると、closureBind{ nonnil }の中に入る場合にデータを取得した状態になっている。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment