Last active
July 31, 2020 04:05
-
-
Save serhiybutz/e613405302c1b5ac35d9e7fbfbb0df31 to your computer and use it in GitHub Desktop.
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
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