Skip to content

Instantly share code, notes, and snippets.

@tornikegomareli
Created July 9, 2023 19:12
Show Gist options
  • Save tornikegomareli/f8ac9e45b9ce5e1ef745907708f58bd1 to your computer and use it in GitHub Desktop.
Save tornikegomareli/f8ac9e45b9ce5e1ef745907708f58bd1 to your computer and use it in GitHub Desktop.
@escaping example
//
// main.swift
// Closures-4Jul2023
//
// Created by Tornike on 04/07/2023.
//
import Foundation
typealias OnAuthenticateCompletion = ((Bool) -> Void)
class MyObservable {
private var listeners: [OnAuthenticateCompletion] = []
func registerCallback(listener: @escaping OnAuthenticateCompletion) {
listeners.append(listener)
}
}
class UserObject {
var myObservable: MyObservable
public init(myObservable: MyObservable) {
self.myObservable = myObservable
}
func register() {
myObservable.registerCallback(listener: { isSuccess in
if isSuccess {
print(self.myObservable)
} else {
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment