Tone analysis on text like Grammarly.
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 | |
| 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. | |
| /// - Does not consider zooming. This has not been tested at all. |
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
| const machine = Machine({ | |
| id: 'some-id', | |
| initial: 'compact', | |
| states: { | |
| compact: { | |
| on: { | |
| PULL_UP: 'expanded', | |
| PULL_DOWN: 'closed' | |
| } | |
| }, |
ℹ️ This article is also available on his blog.
Layout and Drawing are two different things:
- Layout defines only the positions and sizes of all views on screen.
- Drawing specifies how each view is rendered (how it looks).
I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).
- https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170828/date.html
- https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170904/date.html
- https://twitter.com/pedantcoder
My take-aways are:
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
| // 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
| 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! |
