Skip to content

Instantly share code, notes, and snippets.

View helje5's full-sized avatar

Helge Heß helje5

View GitHub Profile
@IanKeen
IanKeen / Convertible.swift
Created April 24, 2020 16:57
PropertyWrapper: Convert to/from raw type during decoding/encoding
import Foundation
public protocol CodingStrategy {
associatedtype Converted
associatedtype RawValue: Codable
static func toRaw(_ value: Converted) throws -> RawValue
static func toValue(_ raw: RawValue) throws -> Converted
}
@IanKeen
IanKeen / Example_Complex.swift
Last active January 23, 2024 07:53
PropertyWrapper: @transaction binding for SwiftUI to make changes to data supporting commit/rollback
struct User: Equatable {
var firstName: String
var lastName: String
}
@main
struct MyApp: App {
@State var value = User(firstName: "", lastName: "")
@State var showEdit = false

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)

@ollieatkinson
ollieatkinson / SVG.swift
Last active May 1, 2024 00:08
Utilise the private CoreSVG framework in Swift
import Darwin
import Foundation
import UIKit
// https://github.com/xybp888/iOS-SDKs/blob/master/iPhoneOS17.1.sdk/System/Library/PrivateFrameworks/CoreSVG.framework/CoreSVG.tbd
// https://developer.limneos.net/index.php?ios=17.1&framework=UIKitCore.framework&header=UIImage.h
@objc
class CGSVGDocument: NSObject { }
@garsdle
garsdle / View+Relative.swift
Last active July 27, 2021 22:40 — forked from IanKeen/View+Relative.swift
SwiftUI relative frame
struct SizePreferenceKey: PreferenceKey {
static var defaultValue: CGSize = .zero
static func reduce(value: inout CGSize, nextValue: () -> CGSize) {
value = nextValue()
}
}
struct RelativeSizeModifier: ViewModifier {
let percentWidth: CGFloat
@IanKeen
IanKeen / View+Discover.swift
Last active February 13, 2024 08:00
SwiftUI: discover underlying components to fill in gaps in SwiftUI api
import SwiftUI
extension View {
public func discover<T: UIView>(
tag: Int = .random(in: (.min)...(.max)),
where predicate: @escaping (T) -> Bool = { _ in true },
_ closure: @escaping (T) -> Void
) -> some View {
self.overlay(
DiscoveryView(tag: tag)
@IanKeen
IanKeen / FocusState.swift
Last active June 30, 2023 17:00
SwiftUI: FocusedState shim for < iOS15
import Combine
import SwiftUI
extension View {
public func focused<T>(file: StaticString = #file, _ state: FocusState<T>, equals value: T) -> some View {
modifier(FocusedModifier(state: state, id: value, file: file))
}
}
@propertyWrapper
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active April 20, 2024 10:41
FormatStyle in Excruciating Detail
import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
import SwiftUI
struct Light: View {
var body: some View {
Circle()
.overlay(rings)
.overlay(
Circle()
.fill(gradient)
.alignmentGuide(VerticalAlignment.center, computeValue: { $0.height/10 })