Skip to content

Instantly share code, notes, and snippets.

View helje5's full-sized avatar

Helge Heß helje5

View GitHub Profile
@helje5
helje5 / SwiftUIDataUnitTest.swift
Created August 17, 2023 16:19
Unit Testing a SwiftUI Query
//
// Created by Helge Heß.
// Copyright © 2023 ZeeZide GmbH.
//
import XCTest
import UIKit
import SwiftData
import SwiftUI
@helje5
helje5 / CompareAnySwift57.swift
Created August 2, 2023 16:20
Compare Any w/ Swift 5.7
func isEqual(_ lhs: Any, _ rhs: Any) -> Bool {
guard let lhs = lhs as? any Equatable else { return false }
func isEqual<T: Equatable>(lhs: T, rhs: Any) -> Bool {
guard let rhs = rhs as? T else { return false }
return lhs == rhs
}
return isEqual(lhs: lhs, rhs: rhs)
}
@helje5
helje5 / ListCellSizingFlicker.swift
Last active October 16, 2023 21:30
ListCellSizingFlicker
import SwiftUI
struct Item: Identifiable {
let id = UUID()
let title = "Hello"
}
let items = [
Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(), Item(),
Item(), Item(), Item(), Item(), Item(), Item(), Item(),
@helje5
helje5 / SVGWebView.swift
Created May 10, 2021 12:54
A SwiftUI View to display SVGs using WKWebView
// Created by Helge Heß on 06.04.21.
// Also available as a package: https://github.com/ZeeZide/SVGWebView
import SwiftUI
import WebKit
/**
* Display an SVG using a `WKWebView`.
*
* Used by [SVG Shaper for SwiftUI](https://zeezide.de/en/products/svgshaper/)
@helje5
helje5 / SwiftData Inverse Relationships.swift
Created September 13, 2023 21:36
SwiftData Inverse Relationships
import SwiftUI
import SwiftData
@Model final class Address {
let street = "Am Geldspeicher 1"
var contact : Contact?
init() {}
}
@Model final class Contact {
@helje5
helje5 / StateObservable.swift
Created September 16, 2023 13:16
An `Observable` property wrapper that only creates the observable value once
/**
* An Observable property wrapper that only creates the observable
* value once.
*
* Example:
* ```swift
* @Observable class Item {
* }
*
* struct MyView: View {
@helje5
helje5 / RepeatedModelInits.swift
Last active September 16, 2023 11:34
Repeated Model Inits w/ State
import SwiftUI
@Observable class Tester {
init() { print("INIT:", ObjectIdentifier(self)) }
deinit { print("DEINIT:", ObjectIdentifier(self)) }
}
struct ContentView: View {
struct Nested: View {
@helje5
helje5 / SparkleCommands.swift
Last active January 11, 2023 00:37
How to hookup Sparkle in SwiftUI
//
// SparkleCommands.swift
// Past for iChat
//
// Created by Helge Heß on 08.04.21.
//
import SwiftUI
#if SPARKLE && canImport(Sparkle)
@helje5
helje5 / servedocc.swift
Last active July 16, 2022 22:24
Small Swift Script to serve `.doccarchive`s to the browser
#!/usr/bin/swift sh
import MacroExpress // @Macro-swift
// MARK: - Parse Commandline Arguments & Usage
func usage() {
let tool = path.basename(process.argv.first ?? "servedocc")
print(
"""
@helje5
helje5 / Tows.swift
Last active June 12, 2022 06:33
An 82-liner SwiftUI script similar to CodeCows 🐮
import SwiftUI
import cows // @AlwaysRightInstitute
struct ContentView: View {
@State var searchString = ""
@State var matches = allCows
@State var selectedCow : String?
let font = Font(NSFont