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
| // Inspired by https://www.atomicbird.com/blog/data-detection-in-swift/ | |
| import Foundation | |
| import XCTest | |
| fileprivate extension URLComponents { | |
| init?(_ url: URL) { | |
| self.init(url: url, resolvingAgainstBaseURL: false) | |
| } | |
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 | |
| import XCTest | |
| extension MutableCollection { | |
| /// Iterates through a mutable collection and mutates values based on the closure argument | |
| /// - Parameter closure: Takes and element and mutates it | |
| mutating func mutatingForEach(_ closure: (inout Element) -> Void) { | |
| indices.forEach { | |
| closure(&self[$0]) |
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 | |
| import XCTest | |
| infix operator >?< : DefaultPrecedence | |
| extension Date { | |
| /// Generate a random date between two dates - Dates do not need to be in order | |
| /// - Parameters: | |
| /// - start: first date | |
| /// - end: second date | |
| /// - Returns: Random `Date` between two dates |
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 PlaygroundSupport | |
| // Print fonts | |
| extension UIFont { | |
| public static func printAllFonts() { | |
| for family in UIFont.familyNames.sorted() { | |
| let names = UIFont.fontNames(forFamilyName: family) | |
| print("Family: \(family)") | |
| names.forEach { |
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 PlaygroundSupport | |
| import XCTest | |
| extension Array { | |
| /// Remove duplicates based on `KeyPath` | |
| /// - Parameter keyPath: Property to determine uniqueness | |
| /// - Returns: `Array` of unique `Elements` based on `keyPath` argument | |
| /// - Complexity Time: O(n) / Space: O(n) | |
| func removingDuplicates<T: Hashable>(by keyPath: KeyPath<Element, T>) -> Self { |
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 | |
| struct CodableUserDefault<Value: Codable> { | |
| let key: String | |
| var wrappedValue: Value? { | |
| get { | |
| UserDefaults.standard.data(forKey: key).flatMap { | |
| try? JSONDecoder().decode(Value.self, from: $0) | |
| } | |
| } |
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 | |
| public protocol NetworkLoggable { | |
| func log<T: CustomStringConvertible>( | |
| label: String, | |
| value: T?, | |
| level: NetworkLogger, | |
| function: StaticString, | |
| line: UInt, | |
| file: 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
| Top: 35 | |
| Sides: 20 | |
| Corner Radius: 10 | |
| (lldb) po tableView.cellForRow(at: .init(row: 0, section: 0))?.frame | |
| ▿ Optional<CGRect> | |
| ▿ some : (0.0, 35.0, 374.0, 44.0) | |
| ▿ origin : (0.0, 35.0) | |
| - x : 0.0 | |
| - y : 35.0 |
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
| /* | |
| Cory Benfield - Building State Machines in Swift | |
| https://www.youtube.com/watch?v=7UC7OUdtY_Q | |
| What is a Finite State Machine? | |
| - Structured way to represent computation | |
| - System can be in one of a finite number of states at any time | |
| - Reacts to inputs by changing state, and optionally producing a side effect | |
| - Deterministic and nondeterministic flavors | |
| - Simple model of computation: easy to understand |