Skip to content

Instantly share code, notes, and snippets.

View helje5's full-sized avatar

Helge Heß helje5

View GitHub Profile
@IanKeen
IanKeen / DictionaryEncoder.swift
Last active May 4, 2021 14:36
DictionaryEncoder for Encodable types
class DictionaryEncoder {
init() { }
func encode(_ value: Encodable) throws -> [String: Any] {
let encoder = _Encoder(codingPath: [])
try value.encode(to: encoder)
guard let result = encoder.value as? [String: Any] else {
throw EncodingError.invalidValue(encoder.value as Any, .init(codingPath: [], debugDescription: "Invalid root container"))
}
@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
struct SortedArray<Element, ComparableProperty: Comparable> {
let propertyAccessor: (Element) -> ComparableProperty
private var elements: [Element]
public init(propertyAccessor: @escaping (Element) -> ComparableProperty) {
self.elements = []
self.propertyAccessor = propertyAccessor
}

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)

import SwiftUI
struct Light: View {
var body: some View {
Circle()
.overlay(rings)
.overlay(
Circle()
.fill(gradient)
.alignmentGuide(VerticalAlignment.center, computeValue: { $0.height/10 })
@phranck
phranck / TassenGugelhupf.swift
Last active March 21, 2023 07:53
Backanleitung fuer einen Tassen-Gugelhupf
// TassenGugelhupf.swift
// Created by Frank Gregor on 18.03.23.
//
// This code compiles perfectly. Just paste it into a Playground and...
// "Let it go"
//
// You nay ask: "Why so complicated?"
// Well, the initial impulse came from this Mastodon thread:
// https://swiftdev.space/@phranck/110045414485613046
//
@IanKeen
IanKeen / Combined+.swift
Last active March 23, 2023 18:21
Combined: A type composed of other types (potential alternative to my Partial<T> type)
@dynamicMemberLookup
struct Combined<A, B> {
private let a: A
private let b: B
init(a: A, b: B) { (self.a, self.b) = (a, b) }
subscript<T>(dynamicMember keyPath: KeyPath<A, T>) -> T {
return a[keyPath: keyPath]
}
@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
/// - returns: `true` when dynamic type is `Equatable` and `==` returns `true`, otherwise `false`.
func areEquatablyEqual(_ lhs: Any, _ rhs: Any) -> Bool {
func receiveLHS<LHS>(_ typedLHS: LHS) -> Bool {
guard
let rhsAsLHS = rhs as? LHS
else { return false }
return areEquatablyEqual(typedLHS, rhsAsLHS)
}
return _openExistential(lhs, do: receiveLHS)
}