This file contains hidden or 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
| @objc(PSTArchitecture) class Architecture: NSObject { | |
| /// Check if process runs under Rosetta 2. | |
| /// | |
| /// Use to disable tests that use WebKit when running on Apple Silicon | |
| /// FB8920323: Crash in WebKit memory allocator on Apple Silicon when iOS below 14 | |
| /// Crash is in JavaScriptCore: bmalloc::HeapConstants::HeapConstants(std::__1::lock_guard<bmalloc::Mutex> const&) | |
| @objc class var isRosettaEmulated: Bool { | |
| // Issue is specific to Simulator, not real devices | |
| #if targetEnvironment(simulator) | |
| return processIsTranslated() == EMULATED_EXECUTION |
This file contains hidden or 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 | |
| #if targetEnvironment(simulator) | |
| @_silgen_name("UIAnimationDragCoefficient") func UIAnimationDragCoefficient() -> Float | |
| func simulatorDragCoefficient() -> CFTimeInterval { | |
| let drag = UIAnimationDragCoefficient() | |
| if drag > 1 { | |
| return CFTimeInterval(drag) | |
| } | |
| return 1 |
This file contains hidden or 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
| # Quick and easy one line command to setup a global .gitignore file and ignore macOS .DS_store files globally | |
| git config --global core.excludesfile "~/.gitignore" && echo .DS_Store >> ~/.gitignore |
This file contains hidden or 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 | |
| extension View { | |
| /// https://stackoverflow.com/a/61985678/3393964 | |
| public func cursor(_ cursor: NSCursor) -> some View { | |
| self.onHover { inside in | |
| if inside { | |
| cursor.push() | |
| } else { | |
| NSCursor.pop() |
This file contains hidden or 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
| { | |
| "global": { | |
| "check_for_updates_on_startup": true, | |
| "show_in_menu_bar": true, | |
| "show_profile_name_in_menu_bar": false | |
| }, | |
| "profiles": [ | |
| { | |
| "complex_modifications": { | |
| "parameters": { |
This file contains hidden or 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 | |
| protocol ViewModelContainable: View { | |
| associatedtype ViewModel : ObservableObject | |
| init(model: ViewModel) | |
| } | |
| // This struct is a direct MVVM alternative to @StateObject in iOS 14 and Mac OS Big Sur. |
This file contains hidden or 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 UIKit | |
| extension Color { | |
| var uiColor: UIColor { | |
| if #available(iOS 14, *) { | |
| // iOS 14 introduces an API to convert SwiftUI.Color to UIKit.UIColor | |
| // but it does not produce a color which reacts to changes in color scheme | |
| // (light mode/dark mode). To make that work we need to extract the color |
This file contains hidden or 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 extension Publisher where Failure == Never { | |
| /// Assigns each element from a Publisher to a property on an object **and holds that objet weakly**. | |
| /// | |
| /// `Combine`'s `assign` holds `object` with a strong reference, causing memory leaks on most use cases. Problem discussion and code origin [here](https://forums.swift.org/t/does-assign-to-produce-memory-leaks/29546/11) | |
| /// | |
| /// - Parameters: | |
| /// - keyPath: The key path of the property to assign. | |
| /// - object: The object on which to assign the value. | |
| /// - Returns: A cancellable instance; used when you end assignment of the received value. Deallocation of the result will tear down the subscription stream. | |
| func assignWeakly<Root: AnyObject>(to keyPath: ReferenceWritableKeyPath<Root, Output>, on object: Root) -> AnyCancellable { |
This file contains hidden or 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 Combine | |
| import Foundation | |
| class ObservablePublisher<T, U: Error>: ObservableObject { | |
| var result: Result<T, U>? | |
| var value: T? { | |
| if let result = self.result, case .success(let value) = result { | |
| return value | |
| } |
This file contains hidden or 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 { |