Check out the repo instead. The Wisdom of Quinn Now with 100% more archived PDFs.
Informative DevForum posts from everyone's favorite DTS member.
(Arranged newest to oldest)
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")) | |
} |
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 | |
} |
Check out the repo instead. The Wisdom of Quinn Now with 100% more archived PDFs.
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 }) |
// 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 | |
// |
@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] | |
} |
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) | |
} |