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
enum DeviceScreenType { | |
case fourOrLess, five, six, sixPlus | |
} | |
struct DeviceHelper { | |
static var screenType: DeviceScreenType { | |
let maxScreenLength = max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height) | |
if maxScreenLength < 568.0 { | |
return .fourOrLess |
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 | |
protocol TextFieldKeyboardPresentable: class, UITextFieldDelegate { | |
/// Collection of all fields in a form in the order in which they should be navigated | |
var textFields: [UITextField] { get } | |
/// Can be used to take action once a form is completely filled out | |
func lastTextFieldDidReturn() | |
/// Can be used to enable a button when text field(s) become valid | |
func checkValidation() |
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 CoreData | |
/// Use `ContextGenerator.contextForDatabase(named:)` to generate an NSManagedObjectContext for interacting with CoreData | |
class ContextGenerator: NSObject { | |
class func contextForDatabase(named databaseName: String, inMemoryOnly: Bool = false) -> NSManagedObjectContext? { | |
return ContextGenerator.init(databaseName: databaseName, inMemoryOnly: inMemoryOnly)?.managedObjectContext | |
} | |
private let managedObjectContext: NSManagedObjectContext | |
private let managedObjectModel: NSManagedObjectModel |
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 | |
protocol JSONUpdatable { | |
func update(with json: JSON) | |
} |
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 String { | |
func removePrefix(_ prefixString: String) -> String { | |
guard self.hasPrefix(prefixString) else { | |
return self | |
} | |
let index = self.index(self.startIndex, offsetBy: prefixString.characters.count) | |
return self.substring(from: index) | |
} | |
} |
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 | |
protocol ScrollToRefreshable: UIScrollViewDelegate { | |
var refreshableScrollView: UIScrollView { get } | |
var activityIndicatorView: UIActivityIndicatorView! { get } | |
func updateViewModel() | |
} | |
extension ScrollToRefreshable { |
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 | |
/// Have a UIViewController adopt this to easily block interactions while loading. | |
protocol LoadingOverlayDisplayable: class { | |
var loadingOverlayView: LoadingOverlayView? { get set } | |
} | |
extension LoadingOverlayDisplayable where Self: UIViewController { | |
/// Call in `viewDidLoad` to establish the loading overlay view |
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
class Stopwatch { | |
static let shared = Stopwatch() | |
let name: String | |
var shouldLogInRealTime: Bool = false | |
private var start: Date? { | |
willSet { | |
lap = newValue | |
} |
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 | |
/// Used to mark text for localization. Keys include the class using the text and the first 10 characters of the default text. | |
protocol Localizable {} | |
extension Localizable { | |
static func localize(_ text: String) -> String { | |
let caller = String(describing: Self.self) | |
let prefixIndex = text.index(text.startIndex, offsetBy: min(15, text.count)) |