Skip to content

Instantly share code, notes, and snippets.

View pteasima's full-sized avatar

Petr Sima pteasima

  • simapps s.r.o.
  • Prague, Czech Republic
  • X @pteasima
View GitHub Profile
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
//
// ContentView.swift
// NavigationViewTest
//
// Created by Thomas Visser on 04/11/2019.
// Copyright © 2019 Thomas Visser. All rights reserved.
//
import SwiftUI
@pteasima
pteasima / Auth+Combine.swift
Last active February 6, 2021 13:52
Firebase + Combine extensions
import FirebaseAuth
import Combine
extension PublishersNamespace where Base: FirebaseAuth.Auth {
var currentUser: AnyPublisher<User?, Never> {
let userSubject = PassthroughSubject<User?, Never>()
let handle = base.addStateDidChangeListener { auth, user in
userSubject.send(user)
}
//
// ContentView.swift
// Layout
//
// Created by Matt Gallagher on 7/6/19.
// Copyright © 2019 Matt Gallagher. All rights reserved.
//
import SwiftUI
@AliSoftware
AliSoftware / Bindings.swift
Last active May 4, 2024 06:18
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
//
// main.swift
// IncrementalWithChanges
//
// Created by Chris Eidhof on 15.08.18.
// Copyright © 2018 objc.io. All rights reserved.
//
import Foundation
@chriseidhof
chriseidhof / alt.swift
Last active August 21, 2018 05:30
Type-Safe Codable Alternative
import Foundation
protocol Representable {
associatedtype Result
}
struct ProdR<A,B>: Representable where A: Representable, B: Representable {
let a: A
let b: B
enum Command {
case buttonTapped
case textChanged(String)
}
enum SideEffect<C> {
case anEvent(C)
case readFile((String) -> C)
// ...
}
//: [Previous](@previous)
import Foundation
protocol Changable {
associatedtype Change
mutating func apply(_ diff: Change)
}
extension Array: Changable {
//: [Previous](@previous)
import Foundation
struct Counter {
var name: String = ""
var age: Int = 33
enum Action {
case increment