Skip to content

Instantly share code, notes, and snippets.

View srdanrasic's full-sized avatar

Srđan Rašić srdanrasic

View GitHub Profile
enum Stylesheet {
enum Product {
static let title = Style<UILabel> {
$0.font = .systemFont(ofSize: 12)
$0.textColor = .red
$0.numberOfLines = 2
}
extension UIView {
public convenience init<V>(style: Style<V>) {
self.init(frame: .zero)
apply(style)
}
public func apply<V>(_ style: Style<V>) {
guard let view = self as? V else {
print("💥 Could not apply style for \(V.self) to \(type(of: self))")
public struct Style<View: UIView> {
public let style: (View) -> Void
public init(_ style: @escaping (View) -> Void) {
self.style = style
}
public func apply(to view: View) {
style(view)
public class ProductView: UIView {
public let titleLabel: UILabel = {
let label = UILabel()
label.font = .systemFont(ofSize: 12)
label.textColor = .red
label.numberOfLines = 2
return label
}()
public class Authentication {
public typealias Credentials = (username: String, password: String)
public enum Response {
case authenticated(Token)
case failed(String)
}
public let credentials: SafeObserver<Credentials>
open class Client {
open func response<Resource, Error: Swift.Error>(for request: Request<Resource, Error>) -> Signal<Resource, Client.Error>
}
public class SafeClient {
public let errors = SafeSignal<UserFriendlyError>()
public init(wrapping client: Client)
public func response<Resource, Error: Swift.Error>(for request: Request<Resource, Error>) -> SafeSignal<Resource>
}
public struct LocalDate {
public let day: Int
public let month: Int
public let year: Int
public init(day: Int, month: Int, year: Int) {
self.day = day
self.month = month
self.year = year
}
extension RecipeList {
public func createScene() -> UIViewController {
let vc = ViewController.RecipeList()
vc.sortDescriptorPickerView.reactive.selectedDescriptor
.observe(with: sortDescriptor)
.dispose(in: vc.reactive.bag)
extension Authentication {
public typealias Scene = (
viewController: UIViewController,
token: SafeSignal<Token>
)
public func createScene() -> Scene {
let vc = ViewController.Authentication()
extension Interactor {
public func createScene() -> Output {
...
}
}