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
| var versionLabelText: String { | |
| guard let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, | |
| let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String | |
| else { return "" } | |
| return "App Version: " + version + "." + build | |
| } |
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 TimeZoneDisplay { | |
| struct TimeZone { | |
| let abbreviation: String | |
| let description: String | |
| let isDaylightSavingsParticipant: Bool | |
| } | |
| var timeZones = [TimeZone]() | |
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
| /// Select two prime numbers `p` and `q` (generally very large numbers, but using small numbers due to limitations of UInt) | |
| let p: UInt = 5 | |
| let q: UInt = 7 | |
| /// `n` is the product of `p` and `q` | |
| let n: UInt = p * q //35 | |
| /// `r` is `(p - 1) * (q - 1)` | |
| let r: UInt = (p-1) * (q-1) //24 |
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 ^^ : AdditionPrecedence | |
| extension Int { | |
| /// Add `n` to each digit, exclude carry. e.g. | |
| /// ~~~ | |
| /// let shifted = 1945.shiftedUp(by: 2) // 3167 | |
| /// ~~~ |
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 | |
| } |
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
| // 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
| 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
| 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
| 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 { |