Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Luke Redpath lukeredpath

🏠
Working from home
View GitHub Profile
@lukeredpath
lukeredpath / AutocompleteWeirdness-1.swift
Created May 4, 2021
Xcode autocomplete behaviour depends on source order
View AutocompleteWeirdness-1.swift
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>
View test.swift
// 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 Apr 7, 2021
Unwrapping embedded case values in TCA test store tests
View LICENSE
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 Aug 4, 2021
An enum equivalent of IfLetStore for The Composable Architecture
View ExampleDomain.swift
enum AppState: Equatable {
case featureOne(FeatureState)
case featureTwo(FeatureState)
case featureThree(FeatureState)
}
enum AppAction: Equatable {
case featureOne(FeatureAction)
case featureTwo(FeatureAction)
case featureThree(FeatureAction)
View CryptoKitCodeChallenge.swift
extension Data {
// Returns a base64 encoded string, replacing reserved characters
// as per https://tools.ietf.org/html/rfc7636#section-4.2
func pkce_base64EncodedString() -> String {
base64EncodedString()
.replacingOccurrences(of: "+", with: "-")
.replacingOccurrences(of: "/", with: "_")
.replacingOccurrences(of: "=", with: "")
.trimmingCharacters(in: .whitespaces)
}
View hexdigest.swift
private func hexString(_ iterator: Array<UInt8>.Iterator) -> String {
return iterator.map { String(format: "%02x", $0) }.joined()
}
let exampleVerifier = "kM83K571n5KFW9u29Xu2qSqgoUwep4I2jZw8FGZg4Yr"
let verifierData = exampleVerifier.data(using: .utf8)!
// CommonCrypto implementation
var buffer = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))
_ = verifierData.withUnsafeBytes { CC_SHA256($0.baseAddress, CC_LONG(verifierData.count), &buffer) }
@lukeredpath
lukeredpath / RawRepresentable+Parsing.swift
Created Jan 3, 2021
Swift enum parsing using the swift-parsing library
View RawRepresentable+Parsing.swift
extension RawRepresentable where Self.RawValue == String {
/// Parses out the first matching raw value from a list of possible values, or returns nil.
///
/// Example:
///
/// enum SomeValues: String, CaseIterable {
/// case one
/// case two
/// }
///
View TaggedOutput.swift
struct TaggedOutput<Output> {
let token: AnyHashable
let output: Output
}
struct Effect<Output>: Publisher {
typealias Failure = Never
let base: AnyPublisher<TaggedOutput<Output>, Failure>
let token: AnyHashable
View gist:0ba9ea748cf0ad90a64b5fa1dde4c3a1
2020-08-04 19:56:05.471109+0100 AudioSimulatorBug[5723:385998] libMobileGestalt MobileGestaltCache.c:38: No persisted cache on this platform.
2020-08-04 19:56:05.494965+0100 AudioSimulatorBug[5723:385162] [SceneConfiguration] Encoded configuration for UIWindowSceneSessionRoleApplication contained a UISceneDelegate class named "(null)", but no class with that name could be found.
2020-08-04 19:56:10.523921+0100 AudioSimulatorBug[5723:385162] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10004003
2020-08-04 19:56:15.525034+0100 AudioSimulatorBug[5723:385162] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10004003
2020-08-04 19:56:15.525272+0100 AudioSimulatorBug[5723:385162] HALDefaultDevice::Initialize: couldn't add the default input device listener, Error: 268451843 (\^P)
2020-08-04 19:56:20.525255+0100 AudioSimulatorBug[5723:385162] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10004003
2020-08-04 19:56:2
View gist:e9485d0d83e6b5f7acea2eedb98e144c
2020-07-23 17:54:20.302611+0100 Poker Clock[15031:1458990] libMobileGestalt MobileGestaltCache.c:38: No persisted cache on this platform.
2020-07-23 17:54:25.428029+0100 Poker Clock[15031:1454775] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10004003
2020-07-23 17:54:30.429086+0100 Poker Clock[15031:1454775] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10004003
2020-07-23 17:54:30.429312+0100 Poker Clock[15031:1454775] HALDefaultDevice::Initialize: couldn't add the default input device listener, Error: 268451843 (\^P)
2020-07-23 17:54:35.430178+0100 Poker Clock[15031:1454775] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10004003
2020-07-23 17:54:35.430464+0100 Poker Clock[15031:1454775] HALDefaultDevice::Initialize: couldn't add the default output device listener, Error: 268451843 (\^P)
2020-07-23 17:54:40.431523+0100 Poker Clock[15031:1454775] HALCADClient::ConnectToServer: failed to find the AHS su