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 XCTest | |
// Credits: https://github.com/pointfreeco/swift-composable-architecture | |
//swiftlint:disable empty_string force_cast force_unwrapping unused_closure_parameter function_body_length | |
class MyCustomTestCase: XCTestCase { | |
func assertEqual<T: Equatable>( | |
expected: T, | |
actual: T | |
) { |
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
@implementation NSApplication (OpenAtLogin) | |
#pragma clang diagnostic push | |
#pragma clang diagnostic ignored "-Wdeprecated-declarations" | |
- (BOOL)openAtLogin | |
{ | |
LSSharedFileListItemRef loginItem = [self loginItem]; | |
BOOL result = loginItem ? YES : NO; |
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
clean: | |
@# just delete specific directories instead of .builds so we don't | |
@# have to re-fetch dependencies | |
@rm -f .build/debug | |
@rm -rf .build/x86_64-apple-macosx/ | |
@rm -rf .build/x86_64-unknown-linux/ | |
@rm -rf .build/x86_64-unknown-linux-gnu/ | |
macos-spm-4.2: clean | |
@echo |
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 SwiftUI | |
// Note: There are some issues with using these modifiers inside of ButtonStyles on macOS. Please see https://twitter.com/noahsark769/status/1288256379640139776?s=20 for more info. | |
struct ConditionalContent<TrueContent: View, FalseContent: View>: View { | |
let value: Bool | |
let trueContent: () -> TrueContent | |
let falseContent: () -> FalseContent | |
@ViewBuilder var body: some View { |
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
// Run any SwiftUI view as a Mac app. | |
import Cocoa | |
import SwiftUI | |
NSApplication.shared.run { | |
VStack { | |
Text("Hello, World") | |
.padding() | |
.background(Capsule().fill(Color.blue)) |
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 Contact: Decodable, CustomStringConvertible { | |
var id: String | |
@NestedKey | |
var firstname: String | |
@NestedKey | |
var lastname: String | |
@NestedKey | |
var address: String | |
enum CodingKeys: String, NestableCodingKey { |
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 CustomMatcher<Value> { | |
let closure: (Value) -> Bool | |
static func ~= (caseValue: CustomMatcher<Value>, switchValue: Value) -> Bool { | |
caseValue.closure(switchValue) | |
} | |
static func ~= (caseValue: Value, switchValue: CustomMatcher<Value>) -> Bool { | |
switchValue.closure(caseValue) | |
} | |
} |
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
extension Publisher { | |
func cancellable<Id: Hashable>(id: Id) -> AnyPublisher<Output, Failure> { | |
return Deferred { () -> PassthroughSubject<Output, Failure> in | |
cancellables[id]?.cancel() | |
let subject = PassthroughSubject<Output, Failure>() | |
cancellables[id] = self.subscribe(subject) | |
return subject | |
} | |
.eraseToAnyPublisher() |
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
// In the Point-Free series on application architecture and state management, | |
// they define a series of ways to compose reducers. Sometimes, however, it seems | |
// that the signature of reducers can complicate the signature of these different | |
// compositions. I found creating a typealias for reducers separated the concern of | |
// understanding the concept of reducers and understanding their higher order | |
// constructions, especially when starting to write my own. | |
// Adding a typealias for Reducer can make certain parts a bit more readable | |
typealias Reducer<Value, Action> = (inout Value, Action) -> Void |
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 SwiftUI | |
import Combine | |
struct AdaptsToSoftwareKeyboard: ViewModifier { | |
@State var currentHeight: CGFloat = 0 | |
func body(content: Content) -> some View { | |
content | |
.padding(.bottom, currentHeight) | |
.edgesIgnoringSafeArea(.bottom) |
NewerOlder