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 __ValueType__ { | |
} | |
struct __ValueType__Key: EnvironmentKey { | |
static var defaultValue = __ValueType__() | |
} | |
extension EnvironmentValues { | |
var __KeyName__: __ValueType__ { | |
get { |
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 { | |
public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> { | |
flatMapError { _ in | |
.init { try handler() } | |
} | |
} | |
public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> { | |
flatMapError { error in | |
.init { try handler(error) } |
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
// Copyright © 2020 Michael Gubik. All rights reserved. Created on 2020-05-16. | |
import Foundation | |
#if TEST | |
import Sentry | |
#endif | |
// maybe look into os_log: https://stackoverflow.com/a/25951564/11588848 | |
private enum LogLevel: String { |
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 | |
@available(iOS 14.0, *) | |
public struct ColorPickerWithoutLabel: UIViewRepresentable { | |
@Binding var selection: Color | |
var supportsAlpha: Bool = true | |
public init(selection: Binding<Color>, supportsAlpha: Bool = true) { | |
self._selection = selection | |
self.supportsAlpha = supportsAlpha |
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 ContentView: View { | |
var body: some View { | |
Image(nsImage: NSImage(named: .init(NSImage.applicationIconName))!) | |
.resizable() | |
.frame(width: 100, height: 100) | |
.tapWithHighlight(onTap: { | |
print("Tap") | |
}, onLongPress: { | |
print("Long Press") | |
}) |
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
class ViewController: UIViewController { | |
@IBAction func onSearch(_ sender: Any) { | |
let fakeWindow = UIWindow(windowScene: view.window!.windowScene!) | |
let fakeTextField = UITextField() | |
fakeTextField.autocorrectionType = .no | |
fakeWindow.addSubview(fakeTextField) | |
fakeWindow.makeKeyAndVisible() | |
fakeTextField.becomeFirstResponder() |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
@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 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 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() |