Skip to content

Instantly share code, notes, and snippets.

@serhiybutz
Last active July 31, 2020 04:05
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 serhiybutz/e613405302c1b5ac35d9e7fbfbb0df31 to your computer and use it in GitHub Desktop.
Save serhiybutz/e613405302c1b5ac35d9e7fbfbb0df31 to your computer and use it in GitHub Desktop.
protocol TargetAction {
associatedtype Theme: ThemeProtocol
func applyTheme(_ theme: Theme)
}
struct AnyTargetActionWrapper<Theme: ThemeProtocol>: TargetAction {
private let _applyTheme: (Theme) -> ()
init<Target: AnyObject>(
target: Target,
action: @escaping (Target) -> (Theme) -> ()
) {
self._applyTheme = { [weak target] theme in
guard let target = target else { return; }
action(target)(theme)
}
}
func applyTheme(_ theme: Theme) -> () {
_applyTheme(theme)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment