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 | |
| let colors = [ | |
| Color.pink, | |
| Color.blue, | |
| Color.green, | |
| Color.orange, | |
| Color.purple, | |
| Color.black, | |
| ] |
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
| @propertyWrapper | |
| public struct AnyProxy<EnclosingSelf, Value> { | |
| private let keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value> | |
| public init(_ keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>) { | |
| self.keyPath = keyPath | |
| } | |
| @available(*, unavailable, message: "The wrapped value must be accessed from the enclosing instance property.") | |
| public var wrappedValue: 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
| //: ## Demo | |
| struct User: CustomStringConvertible { | |
| let name: String | |
| let age: Int | |
| var description: String { "\(name) (\(age))" } | |
| } | |
| let users = [ | |
| User(name: "Bob", age: 22), |
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 Contact: Decodable, CustomStringConvertible { | |
| var id: String | |
| @NestedKey | |
| var firstname: String | |
| @NestedKey | |
| var lastname: String | |
| @NestedKey | |
| var address: String | |
| enum CodingKeys: String, NestableCodingKey { |
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 Foundation | |
| // Diff values for better test assertions. | |
| // | |
| // Enums and collections left as an exercise for the reader. | |
| // A difference between two values | |
| struct Difference: CustomStringConvertible { | |
| let path: String | |
| let actual: String |
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 | |
| extension UIView { | |
| var allSubviews: [UIView] { | |
| subviews + subviews.flatMap { $0.allSubviews } | |
| } | |
| func firstSubview<T: UIView>(of type: T.Type) -> T? { | |
| allSubviews.first { $0 is T } as? T |
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
| // Created by Sean Heber (@BigZaphod) on 10/12/19. | |
| // License: BSD | |
| import Foundation | |
| //==--------------------------------------------------------- | |
| /// This implementation requires the ability to initialize an | |
| /// instance of a type before it can decode it. This is to support | |
| /// reference types automatically so that each instance is | |
| /// only stored once in the archive. Decoding a reference |