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
// | |
// DebugDevice.swift | |
// | |
// Copyright 2022 • Sidetrack Tech Limited | |
// | |
import Foundation | |
// This must be called on the main-thread. | |
var isDebugProfileInstalled: Bool { |
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
//How to use BaseState struct to share state between views in TCA architecture. | |
// https://forums.swift.org/t/best-practice-for-sharing-data-between-many-features/37696/4 | |
//This is a proof-of-concept only; it simply is an attempt to model how to get and set global shared state among different views in a TCA-style app. | |
import SwiftUI | |
import ComposableArchitecture | |
@dynamicMemberLookup | |
struct TCABaseState<State: Equatable>: Equatable{ |
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 | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 0) { | |
Color.green | |
Color.green | |
Color.green | |
Color.yellow | |
Color.orange |
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 Color { | |
/// Return a random color | |
static var random: Color { | |
return Color( | |
red: .random(in: 0...1), | |
green: .random(in: 0...1), | |
blue: .random(in: 0...1) | |
) | |
} | |
} |
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 Result { | |
func tryMap<T>(_ transform:(Success) throws -> T) -> Result<T, Swift.Error> { | |
switch self { | |
case let .success(success): | |
do { | |
return .success(try transform(success)) | |
} catch { | |
return .failure(error) | |
} | |
case let .failure(failure): |
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 UIKit | |
class AutoUpdateColor: UIColor { | |
convenience init(lightColor: UIColor, darkColor: UIColor) { | |
if #available(iOS 13.0, *) { | |
self.init { | |
traitCollection in | |
traitCollection.userInterfaceStyle == .dark | |
? darkColor | |
: lightColor | |
} |
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 UIHostingController { | |
convenience public init(rootView: Content, ignoreSafeArea: Bool) { | |
self.init(rootView: rootView) | |
if ignoreSafeArea { | |
disableSafeArea() | |
} | |
} | |
func disableSafeArea() { |
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/Foundation.h> | |
// clang -o main -framework Foundation main.m | |
int main(int argc, const char*argv[]) { | |
@autoreleasepool { | |
NSLog(@"%@", (@42).class); // __NSCFNumber | |
NSLog(@"%@", (@YES).class); // __NSCFBoolean | |
NSLog(@"%@", @"Hello".class); // __NSCFConstantString | |
NSLog(@"%@", [NSString stringWithFormat:@"%d", 42].class); // NSTaggedPointerString |
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
////===--- EitherSequence.swift - A sequence type-erasing two sequences -----===// | |
//// | |
//// This source file is part of the Swift.org open source project | |
//// | |
//// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | |
//// Licensed under Apache License v2.0 with Runtime Library Exception | |
//// | |
//// See https://swift.org/LICENSE.txt for license information | |
//// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | |
//// |
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)) |
NewerOlder