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 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 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
| // 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 Compression | |
| import XCTest | |
| extension Encodable { | |
| /// Returns a string object describing the encodable object's byte size using `ByteCountFormatter`. Or a description of the `DecodingError` generated during the decoding process | |
| var size: String { | |
| do { | |
| return try JSONEncoder().encode(self).size | |
| } catch { |
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 XCTest | |
| extension Array { | |
| /// Determine if an `Array` contains an element by a specific property using a Binary Search Algorithm | |
| /// - Parameters: | |
| /// - searchItem: Element with property to search for | |
| /// - keyPath: KeyPath of property to search for | |
| /// - isSorted: Whether or not the `Array` is ordered. Default value is `true` | |
| /// - Returns: `true` if `Array` contains `searchItem` KeyPath, `false` if it does not |
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 Person { | |
| fileprivate final class Storage { | |
| var name: String | |
| var age: UInt8 | |
| init(name: String, age: UInt8) { | |
| self.name = name | |
| self.age = age | |
| } | |
| } |
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
| // Inspiration from TweetleDumb by Ian Keen | |
| final class FooCell: UITableViewCell { | |
| let label = UILabel() | |
| override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | |
| super.init(style: style, reuseIdentifier: reuseIdentifier) | |
| layout() | |
| } | |
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 Versioned<Value> { | |
| private var currentValue: Value | |
| private(set) var history = VersionHistory() | |
| init(wrappedValue: Value) { | |
| self.currentValue = wrappedValue | |
| } | |
| 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
| import Foundation | |
| import XCTest | |
| enum Bit: Int, CustomDebugStringConvertible { | |
| case zero = 0 | |
| case one | |
| var debugDescription: String { | |
| rawValue.description | |
| } |