Skip to content

Instantly share code, notes, and snippets.


Marcin Krzyzanowski krzyzanowskim

View GitHub Profile
View gist:ff97dc8770aaf3089f270a5294ccc26c
import Foundation
import Combine
public struct CombineManyLatest<Upstream: Publisher>: Publisher {
public init(_ upstream: Upstream...) {
self.upstream = upstream
public init(_ upstream: [Upstream]) {
self.upstream = upstream
krzyzanowskim / PastelColor.swift
Last active Jul 28, 2022
Random pastel colors
View PastelColor.swift
struct ContentView: View {
@State var color: Color = .Pastel.random()
var body: some View {
.onTapGesture {
color = .Pastel.random()
View 202207041909 AppStorage extension for strongly typed

202207041909 AppStorage extension for strongly typed keys

#appstorage #swiftui

The @AppStorage property wrapper for observable access to UserDefaults keys is stringified.

To get a strongly typed key access, I oriented myself on the @Environment(\.keyPath) wrapper and my experience with SwiftyUserDefaults and its subscript-based access.

// Use defaultValue from the key:
@AppStorage(\.showOnboarding) var showOnboarding
View Indirect.swift
// A Swift property wrapper for adding "indirect" to struct properties.
// Enum supports this out of the box, but for some reason struct doesn't.
// This is useful when you want to do something recursive with structs like:
// struct Node {
// var next: Node?
// }
theevilbit /
Last active Apr 25, 2022
Download All Apple OSS Tarballs from Github
: '
You need a personal access token for GitHub to avoid hitting the rate limit. Refer to the docs:
krzyzanowskim / StringGetSizeThatFits.swift
Last active Apr 10, 2022
Calculate frame of String, that fits given width
View StringGetSizeThatFits.swift
// Excerpt from
// Licence BSD-2 clause
// Marcin Krzyzanowski
func getSizeThatFits(_ attributedString: NSAttributedString, maxWidth: CGFloat) -> CGSize {
let framesetter = CTFramesetterCreateWithAttributedString(attributedString)
let rectPath = CGRect(origin: .zero, size: CGSize(width: maxWidth, height: 50000))
let ctFrame = CTFramesetterCreateFrame(framesetter, CFRange(), CGPath(rect: rectPath, transform: nil), nil)
nicklockwood / CodableVersioning.swift
Last active Oct 17, 2022
Example demonstrating how to use versioning for Codable structs
View CodableVersioning.swift
// This gist demonstrates how you can implement versioning for a Codable struct to support loading
// old serialized data after changing the structure. Notable features of this solution:
// * No need to make new properties optional, or to perform post-processing on the struct after
// loading in ordeer to populate missing values
// * No need to change the call site - from the outside this struct behaves just the same
// as if we had implemented codable directly in the normal way.
// * Versioning can be applied individually to parents or leaves in a larger tree of
// structs without affecting the other elements
// * This approach will work even if the original struct was not designed with versioning in mind

This page is now depreacted!

Check out the repo instead. The Wisdom of Quinn Now with 100% more archived PDFs.

The Wisdom of Quinn

Informative DevForum posts from everyone's favorite DTS member.

(Arranged newest to oldest)

View boilerplate.swift
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI {
VStack {
Text("Hello, World")
chriseidhof / sample.swift
Last active Nov 30, 2022
View Inspection
View sample.swift
import SwiftUI
struct SizeKey: PreferenceKey {
static func reduce(value: inout CGSize?, nextValue: () -> CGSize?) {
value = value ?? nextValue()
struct ContentView: View {
@State var width: CGFloat? = nil
var body: some View {