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 | |
| #if os(macOS) | |
| public typealias Font = NSFont | |
| public typealias FontDescriptor = NSFontDescriptor | |
| #else | |
| public typealias Font = UIFont | |
| public typealias FontDescriptor = UIFontDescriptor | |
| #endif |
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
| # A Best in Class Checklist | |
| A boiled down checklist adapted from this [post](https://www.swiftjectivec.com/a-best-in-class-app/), created by @jordanmorgan10. | |
| > To use this, create a Github Issue in your own repo, and simply copy and paste this text. | |
| ## iOS Core Technology | |
| _Things any iOS app can benefit from_ | |
| - [ ] iCloud Sync | |
| - [ ] Focus Filter Support |
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
| // Avoids the keyboard in a UIKit app by leveraging additionalSafeAreaInsets. | |
| // You can put this in the root view controller so the whole app will avoid the keyboard. | |
| // Only tested on iOS 13.3. | |
| // Made for https://douglashill.co/reading-app/ | |
| @objc func updateSafeAreaForKeyboardFromNotification(_ notification: Notification) { | |
| guard let endFrameInScreenCoords = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { | |
| return | |
| } | |
| // Please consider whether the force unwrap here is safe for your own use case. |
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
| // Douglas Hill, November 2019 | |
| // Find the latest version of this file at https://github.com/douglashill/KeyboardKit | |
| import UIKit | |
| /// A scroll view that allows scrolling using a hardware keyboard like `NSScrollView`. | |
| /// Supports arrow keys, option + arrow keys, command + arrow keys, space bar, page up, page down, home and end. | |
| /// Limitations: | |
| /// - Paging scroll views (isPagingEnabled = true) are not supported yet. | |
| /// - The scroll view must become its own delegate so setting the delegate is not supported yet. |
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
| extension FileManager { | |
| /* | |
| Prints out the locations of the simulator and the shared group folder. | |
| This is useful for debugging file issues. | |
| Example usage: FileManager.default.printFileLocations() | |
| */ | |
| func printFileLocations() { | |
| let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) | |
| let simulatorFolder = paths.last! |
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 XCTest | |
| @_functionBuilder | |
| struct Test<T> { | |
| var data: T | |
| var given: given<T> | |
| var when: when<T> | |
| var then: then<T> | |
| func execute() { |
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
| // Copyright © 2019 Alexey Naumov. MIT License | |
| import Combine | |
| typealias CancelBag = Set<AnyCancellable> | |
| extension CancelBag { | |
| mutating func collect(@Builder _ cancellables: () -> [AnyCancellable]) { | |
| formUnion(cancellables()) | |
| } |
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
| struct StateMachine<State, Action> { | |
| private(set) var state: State | |
| private let transition: (State, Action) -> State? | |
| init(startState: State, transition: @escaping (State, Action) -> State?) { | |
| self.state = startState | |
| self.transition = transition | |
| } | |
| mutating func apply(action: Action) -> Bool { |
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
| @discardableResult | |
| public func with<T>(_ value: T, _ builder: (T) -> Void) -> T { | |
| builder(value) | |
| return value | |
| } | |
| @discardableResult | |
| public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T { | |
| try builder(value) | |
| 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 UIKit | |
| import Foundation | |
| func test(named: String, | |
| _ work: (_ assert: @escaping (Bool) -> Void, _ done: @escaping () -> Void) -> Void) { | |
| var testPass = true | |
| var assertCount = 0 | |
| let assert: (Bool) -> Void = { value in | |
| assertCount = assertCount + 1 | |
| testPass = testPass && value |
NewerOlder