Skip to content

Instantly share code, notes, and snippets.

View couchdeveloper's full-sized avatar

Andreas Grosam couchdeveloper

View GitHub Profile
@marcpalmer
marcpalmer / ScrollViewSnapIssue.swift
Last active October 22, 2023 06:19
Updated to correct problem with subscription being new every time state changes, fixed scrollTo so it works
import Combine
import SwiftUI
struct SnapPointPreferenceData {
let frame: Anchor<CGRect>
}
struct SnapPointPreferenceKey: PreferenceKey {
typealias Value = SnapPointPreferenceData?
@rjchatfield
rjchatfield / ArrayBuilder.swift
Last active February 20, 2025 12:33
ArrayBuilder - Swift ~~FunctionBuilder~~ ResultBuilder
@resultBuilder
public struct ArrayBuilder<Element> {
public static func buildPartialBlock(first: Element) -> [Element] { [first] }
public static func buildPartialBlock(first: [Element]) -> [Element] { first }
public static func buildPartialBlock(accumulated: [Element], next: Element) -> [Element] { accumulated + [next] }
public static func buildPartialBlock(accumulated: [Element], next: [Element]) -> [Element] { accumulated + next }
// Empty Case
public static func buildBlock() -> [Element] { [] }
// If/Else