Skip to content

Instantly share code, notes, and snippets.

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

Luke Redpath lukeredpath

🏠
Working from home
View GitHub Profile
@lukeredpath
lukeredpath / SharedStateDemoApp.swift
Last active March 30, 2024 02:30
Demo of TCA shared state using default-providing key
//
// SharedStateDemoApp.swift
// SharedStateDemo
//
// Created by Luke Redpath on 29/03/2024.
//
import ComposableArchitecture
import SwiftUI
//
// TCAStoreCachingApp.swift
// TCAStoreCaching
//
// Created by Luke Redpath on 11/03/2024.
//
import ComposableArchitecture
import SwiftUI
@lukeredpath
lukeredpath / BindingEqualityTests.swift
Last active July 6, 2023 16:40
BindingEquality bug in TCA 0.55.0
import ComposableArchitecture
import XCTest
struct BindingTestFeature: ReducerProtocol {
struct State: Equatable {
@BindingState
var value: Int = 0
}
enum Action: Equatable, BindableAction {
@lukeredpath
lukeredpath / StoreScope.swift
Created June 16, 2023 19:15
Ergonomic store scoping
struct StoreScope<State, Action, ChildState, ChildAction> {
typealias Scope<_State, _Action> = StoreScope<State, Action, _State, _Action>
typealias ScopeOf<R: ReducerProtocol> = StoreScope<State, Action, R.State, R.Action>
typealias PresentationScope<_State, _Action> = StoreScope<State, Action, PresentationState<_State>, PresentationAction<_Action>>
typealias PresentationScopeOf<R: ReducerProtocol> = StoreScope<State, Action, PresentationState<R.State>, PresentationAction<R.Action>>
var toChildState: (State) -> ChildState
var fromChildAction: (ChildAction) -> Action
}
@lukeredpath
lukeredpath / LICENSE
Last active June 7, 2023 13:02
A wrapper for raw representable values when decoding them from JSON
Copyright 2023 Luke Redpath
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHE
@lukeredpath
lukeredpath / PerceptualImage.swift
Created September 13, 2022 10:15
Perceptual image snapshot strategy
// Taken from https://github.com/pointfreeco/swift-snapshot-testing/pull/628/files
import Foundation
import SwiftUI
@testable import SnapshotTesting
#if os(iOS) || os(tvOS)
import CoreImage.CIFilterBuiltins
import UIKit
@lukeredpath
lukeredpath / AutocompleteWeirdness-1.swift
Created May 4, 2021 14:32
Xcode autocomplete behaviour depends on source order
import Combine
import Foundation
let wrapper = Wrapper(createPublisher: { Just("foo").eraseToAnyPublisher() })
// This will not produce any auto-complete suggestions
wrapper.createPublisher().
struct Wrapper {
var createPublisher: () -> AnyPublisher<String, Never>
// Compiles in Xcode 12.5, but not 12.4
var foo: Foo {
#if DEBUG
Foo(debug: true)
#else
Foo()
#end
}
// Compiles in both
@lukeredpath
lukeredpath / LICENSE
Last active April 7, 2021 14:13
Unwrapping embedded case values in TCA test store tests
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@lukeredpath
lukeredpath / ExampleDomain.swift
Last active January 31, 2023 16:18
An enum equivalent of IfLetStore for The Composable Architecture
enum AppState: Equatable {
case featureOne(FeatureState)
case featureTwo(FeatureState)
case featureThree(FeatureState)
}
enum AppAction: Equatable {
case featureOne(FeatureAction)
case featureTwo(FeatureAction)
case featureThree(FeatureAction)