Skip to content

Instantly share code, notes, and snippets.

let lightThemeModel = MyThemeModel(
appBgColor: .white,
textColor: .black)
let darkThemeModel = MyThemeModel(
appBgColor: .darkGray,
textColor: .white)
@objc protocol Themable {
func applyTheme(_ theme: MyTheme)
}
//
// TitlePosition.swift
// PileCollectionVC
//
// Created by Rik Ki on 11/9/18.
// Copyright © 2018 Rik Ki. All rights reserved.
//
import Foundation
enum MyTheme {
case light
case dark
var settings: MyThemeSettings {
switch self {
case .light: return MyThemeSettings.lightTheme
case .dark: return MyThemeSettings.darkTheme
}
}
}
@objc enum MyTheme: Int {
    case light
    case dark
    var settings: MyThemeSettings {
        switch self {
        case .light: return MyThemeSettings.lightTheme
        case .dark: return MyThemeSettings.darkTheme
        }
    }
}
public protocol ThemeModelProtocol {}
public protocol ThemeProtocol: Equatable {
    associatedtype Model: ThemeModelProtocol
    var settings: Model { get }
}
extension Themer where Theme == MyTheme {
    private static var instance: Themer?
    static var shared: Themer {
        if instance == nil {
            instance = Themer(defaultTheme: .light)
        }
        return instance!
    }
}
@serhiybutz
serhiybutz / code.swift
Created July 18, 2020 13:49
Combine: shareReplay, 01
import Combine
final class ShareReplay<Upstream: Publisher>: Publisher {
typealias Output = Upstream.Output
typealias Failure = Upstream.Failure
var recording = Record<Output, Failure>.Recording()
var upstreamShare: AnyPublisher<Output, Failure>
let bufferCapacity: Int
var subscription: AnyCancellable?
@serhiybutz
serhiybutz / code.swift
Created July 18, 2020 15:25
Combine: shareReplay, 02
import Combine
let measurements = PassthroughSubject<Int, Never>()
let diagramDataSource = measurements
.share(replay: 3)
let subscriber1 = diagramDataSource
.sink(
receiveCompletion: { completion in
@serhiybutz
serhiybutz / code.swift
Created July 20, 2020 22:14
Combine: withLatestFrom, 01
import UIKit
import Combine
extension UITextField {
var textPublisher: AnyPublisher<String?, Never> {
NotificationCenter.default
.publisher(
for: UITextField.textDidChangeNotification,
object: self)
.map(\.object)