Skip to content

Instantly share code, notes, and snippets.

@steipete
steipete / SwiftUIThingsToKnow.swift
Last active February 5, 2023 15:33
10 Things I Wish I Knew When Starting SwiftUI (See also https://gist.github.com/steipete/6c430d08bd57b066fada7628d3b8b719)
- In almost all cases where you type `@ObservedObject`, you really want `@StateObject`.
If you need to support iOS 13, use `@State` on parent and pass value into child with `@ObservedObject` to simulate `@StateObject`.
Pass arguments to that model in `onAppear`. Example: https://github.com/ra1028/SwiftUI-Hooks/blob/main/Sources/Hooks/HookScope.swift#L39-L41
```
.onAppear {
model.onAppear(userTag: userTag)
}
.onDisappear {
model.onDisappear()
import SwiftUI
import Combine
public struct ChangeObserver<V: Equatable>: ViewModifier {
public init(newValue: V, action: @escaping (V) -> Void) {
self.newValue = newValue
self.newAction = action
}
private typealias Action = (V) -> Void
@jessesquires
jessesquires / gitsl.sh
Last active December 3, 2023 07:08
git "smartlog" / "pretty log"
# blog post
#
# https://www.jessesquires.com/blog/customizing-git-log/
git log --graph --pretty=format:'commit: %C(bold red)%h%Creset %C(red)<%H>%Creset %C(bold magenta)%d %Creset%ndate: %C(bold yellow)%cd %Creset%C(yellow)%cr%Creset%nauthor: %C(bold blue)%an%Creset %C(blue)<%ae>%Creset%n%C(cyan)%s%n%Creset'