Skip to content

Instantly share code, notes, and snippets.

View mattadatta's full-sized avatar

Matthew Brown mattadatta

  • Ottawa, ON, Canada
View GitHub Profile
@mattadatta
mattadatta / ObservableState.swift
Last active November 17, 2025 13:55
`@StateObject`-like property wrapper for `@Observable` types that provides an autoclosure initializer.
import SwiftUI
@propertyWrapper
@MainActor
public struct ObservableState<Value: AnyObject & Observable>: @MainActor DynamicProperty {
private final class Storage: ObservableObject {
var value: Value?
@mattadatta
mattadatta / CollectionView.swift
Last active August 11, 2025 04:38
CollectionView.swift - UIKit's UICollectionView implemented in SwiftUI using UIViewRepresentable
//
// SwiftUI `CollectionView` type implemented with UIKit's `UICollectionView` under the hood.
// Implemented using `UIViewRepresentable`, assigning a custom `UIHostingConfiguration` to
// the `contentConfiguration` property of custom `UICollectionViewCell`s.
//
// See below implementation for usage.
//
import SwiftUI
import UIKit