This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public protocol AnalyticsReducer { | |
| associatedtype State | |
| associatedtype Action | |
| func analytics(before: State, after: State, action: Action) -> Effect<Action> | |
| } | |
| public struct _AnalyticsReducer<Base: Reducer, Analytics: AnalyticsReducer>: Reducer where Analytics.State == Base.State, Analytics.Action == Base.Action { | |
| @usableFromInline | |
| let base: Base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| import SwiftUI | |
| extension EnvironmentValues { | |
| public func value<T>(_: T.Type = T.self, forKey key: String) -> T? { | |
| guard let value = first(where: { name($0, equals: key) }) else { | |
| print("No EnvironmentValue with key '\(key)' found.") | |
| return nil | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct LoadingIndicator: View { | |
| @State private var startingOffset: CGFloat = 0 | |
| @State private var space: CGSize = .zero | |
| @State private var size: CGSize = .zero | |
| @State private var progress: Double = 0 | |
| @Binding private var isLoading: Bool { | |
| didSet { | |
| if isLoading { action() } | |
| else { progress = 0 } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public struct Require<Content: View>: View { | |
| @StateObject private var registrar: ViewRegistrar | |
| @ViewBuilder private var content: () -> Content | |
| public init(_ value: Int, @ViewBuilder content: @escaping () -> Content) { | |
| self._registrar = .init(wrappedValue: ViewRegistrar(limit: value)) | |
| self.content = content | |
| } | |
| public var body: some View { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Setup | |
| class Child: ObservableObject { | |
| @Published var value = "" | |
| } | |
| class Parent: ObservableObjectContainer { | |
| let single = Child() | |
| let array = [Child(), Child()] | |
| func updateSingle() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public protocol DynamicProperties: AnyObject { | |
| subscript<T>(dynamic key: String) -> T? { get set } | |
| } | |
| private extension String { | |
| var unsafePointer: UnsafeRawPointer { | |
| return UnsafeRawPointer(bitPattern: hashValue)! | |
| } | |
| } | |
| extension DynamicProperties { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension View { | |
| public func _refreshable(_ action: @escaping () async -> Void) -> some View { | |
| modifier(RefreshableTaskModifier(action: action)) | |
| } | |
| } | |
| private struct RefreshId { | |
| var value: UUID | |
| var continuation: CheckedContinuation<Void, Never> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @propertyWrapper | |
| struct Storage<T: AppStorageConvertible>: RawRepresentable { | |
| var rawValue: String { wrappedValue.storedValue } | |
| var wrappedValue: T | |
| init?(rawValue: String) { | |
| guard let value = T.init(rawValue) else { return nil } | |
| self.wrappedValue = value | |
| } | |
| init(wrappedValue: T) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// A collection that returns the current element as well as the previous and next elements when available | |
| public struct NeighborSequence<Base: Sequence>: Sequence { | |
| public typealias Element = (previous: Base.Element?, current: Base.Element, next: Base.Element?) | |
| private let base: Base | |
| fileprivate init(_ base: Base) { | |
| self.base = base | |
| } | |
NewerOlder