Skip to content

Instantly share code, notes, and snippets.

View shaps80's full-sized avatar
🏠
Working from home

Shaps shaps80

🏠
Working from home
View GitHub Profile
extension View {
func draggable(_ location: Binding<CGPoint>) -> some View {
modifier(DragModifier(location: location))
}
}
struct DragModifier: ViewModifier {
@GestureState private var startLocation: CGPoint? = nil
@Binding var location: CGPoint
import Foundation
public enum Decode {}
public protocol DecodableDefaultSource: Sendable {
associatedtype Value: Decodable & Sendable
static var defaultValue: Value { get }
}
extension Decode {
@shaps80
shaps80 / Sign in with Apple.swift
Created January 29, 2025 20:42
Simplifies sign-in with  integration by providing an Environment-driven action similar to `openWindow` and others.
import SwiftUI
import AuthenticationServices
public struct SignInWithAppleAction: Sendable {
public func callAsFunction() async throws -> ASAuthorization {
try await Coordinator().perform()
}
}
public extension EnvironmentValues {
import Swift
@dynamicMemberLookup
public final class Wrapper<Wrapped> {
public var wrapped: Wrapped
public subscript<T>(dynamicMember keyPath: KeyPath<Wrapped, T>) -> T {
wrapped[keyPath: keyPath]
}
import SwiftUI
public extension View {
func onGeometryChange<T>(
for type: T.Type,
of transform: @escaping (GeometryProxy) -> T,
action: @escaping (_ newValue: T) -> Void
) -> some View where T: Equatable {
modifier(GeometryModifier(transform: transform, action: action))
}
import SwiftUI
extension Backport<Any> {
@MainActor
public struct Group<Content: View>: View, Sendable {
private var content: Content
public init<Base, Result>(
subviewsOf view: Base,
@ViewBuilder transform: @escaping (SubviewsCollection) -> Result
import SwiftUI
public extension Picker where SelectionValue: CaseIterable, SelectionValue.AllCases: RandomAccessCollection, SelectionValue: RawRepresentable, SelectionValue.RawValue == String {
init(_ title: some StringProtocol, selection: Binding<SelectionValue>) where Label == Text, Content == ForEach<SelectionValue.AllCases, SelectionValue, Text> {
self.init(title, selection: selection) {
ForEach(SelectionValue.allCases, id: \.self) { element in
Text(element.rawValue)
}
}
}
@shaps80
shaps80 / Binding+OptionSet.swift
Created September 11, 2024 15:29
Simplifies binding option set values to a SwiftUI View.
import SwiftUI
public extension Binding where Value: OptionSet {
func toggling(_ value: Value.Element) -> Binding<Bool> {
.init(
get: {
wrappedValue.contains(value)
},
set: {
if $0 {
@shaps80
shaps80 / SwiftUI-Interface.swift
Created July 20, 2024 12:56
SwiftUI 5.10 Interface
This file has been truncated, but you can view the full file.
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.10 (swiftlang-5.10.0.12.5 clang-1500.3.9.1.1)
// swift-module-flags: -target arm64e-apple-macos14.4 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Osize -library-level api -library-level api -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -package-name SwiftUI -enable-bare-slash-regex -user-module-version 5.4.38.401 -module-name SwiftUI
import Accessibility
import AppKit
import Combine
import CoreData
import CoreFoundation
@_exported import CoreGraphics
import SwiftUI
public struct Expansions<Value: Hashable>: Equatable {
@Observable
fileprivate final class Wrapper: Equatable {
var expansions: Set<Value>
init(expansions: Set<Value> = []) {
self.expansions = expansions
}