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
import UIKit | |
class DemoViewController: UIViewController { | |
@IBOutlet weak var highlightedLabel: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Subscribe this instance of UIViewController to theme notifications | |
ThemeManager.shared.register( |
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
public protocol ThemeModelProtocol {} | |
public protocol ThemeProtocol: Equatable { | |
associatedtype Model: ThemeModelProtocol | |
var settings: Model { get } | |
} |
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
struct MyThemeSettings: ThemeModelProtocol { | |
let appBgColor: UIColor | |
let highlightedBgColor: UIColor | |
let textColor: UIColor | |
} | |
enum MyTheme: ThemeProtocol { | |
case light | |
case dark | |
var settings: MyThemeSettings { |
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
extension MyThemeSettings { | |
static let lightTheme = MyThemeSettings( | |
appBgColor: .white, | |
highlightedBgColor: .lightGray, | |
textColor: .black | |
) | |
static let darkTheme = MyThemeSettings( | |
appBgColor: .gray, | |
highlightedBgColor: .darkGray, | |
textColor: .white |
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, |
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
import Foundation | |
fileprivate var associatedKey = "ThemerTargetActionStorage" | |
final class TargetActionStorage<Theme: ThemeProtocol> { | |
private var targetActions: [AnyTargetActionWrapper<Theme>] = [] | |
static func setup(for target: Any) -> TargetActionStorage { | |
let storage = TargetActionStorage() | |
objc_setAssociatedObject( |
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
import Foundation | |
final class Themer<Theme: ThemeProtocol> { | |
typealias TargetActionStorageType = TargetActionStorage<Theme> | |
private var targetActionStorages = NSHashTable<TargetActionStorageType> | |
.weakObjects() | |
var theme: Theme { | |
didSet { |
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
extension Themer where Theme == MyTheme { | |
private static var instance: Themer? | |
static var shared: Themer { | |
if instance == nil { | |
instance = Themer(defaultTheme: .light) | |
} | |
return instance! | |
} | |
} |
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
// | |
// TitlePosition.swift | |
// PileCollectionVC | |
// | |
// Created by Rik Ki on 11/9/18. | |
// Copyright © 2018 Rik Ki. All rights reserved. | |
// | |
import Foundation |
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
// | |
// AutosizingTextField.swift | |
// | |
// Created by Serge Bouts on 6/4/20. | |
// Copyright © 2020 Rik Ki. All rights reserved. | |
// | |
import Cocoa | |
final class AutosizingTextField: NSTextField { |