This file contains 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 | |
let isUITesting = /* your UI test detection here */ | |
@main | |
struct EntryPoint { | |
static func main() { | |
if isUITesting { | |
UITestApp.main() |
This file contains 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 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 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 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
struct UserDefaultsKey<T: Codable> { | |
var name: String | |
var `default`: T | |
} | |
extension UserDefaults { | |
func get<T>(_ key: UserDefaultsKey<T>) -> T { | |
guard | |
let data = data(forKey: key.name), | |
let box = try? JSONDecoder().decode(Box<T>.self, from: data) |
This file contains 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 | |
public struct AllowDecodingFailure<T: Codable>: Codable { | |
public var wrappedValue: T? | |
public var error: Error? | |
public var projectedValue: AllowDecodingFailure<T> { self } | |
public init(wrappedValue: T?) { | |
self.wrappedValue = wrappedValue | |
self.error = nil | |
} |
This file contains 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
// MARK: - TCAView | |
public protocol TCAView: View where Body == WithViewStore<ScopedState, ScopedAction, Content> { | |
associatedtype ViewState | |
associatedtype ViewAction | |
associatedtype ScopedState | |
associatedtype ScopedAction | |
associatedtype Content |
This file contains 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 Observation | |
public protocol _Observable: Observable { | |
nonisolated | |
func _access<Member>(keyPath: KeyPath<Self, Member>) | |
nonisolated | |
func _withMutation<Member, MutationResult>( | |
keyPath: KeyPath<Self, Member>, | |
_ mutation: () throws -> MutationResult |
This file contains 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
func debounce<T>(delay: TimeInterval, function: @escaping (T) -> Void, complete: @escaping () -> Void = { }) -> (T) -> Void { | |
let queue = DispatchQueue(label: "Debouncer") | |
var current: DispatchWorkItem? | |
return { input in | |
current?.cancel() | |
let new = DispatchWorkItem { | |
function(input) | |
complete() | |
} |
This file contains 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 wrapper for a partial representation of a `T`. | |
/// It can be constructed over time, then later used to | |
/// build a complete `T` | |
@dynamicMemberLookup | |
public struct Partial<T> { | |
enum Error: Swift.Error { | |
case invalid(PartialKeyPath<T>) | |
} | |
// MARK: - Private Properties |
NewerOlder