I hereby claim:
- I am cassiuspacheco on github.
- I am cassiusop (https://keybase.io/cassiusop) on keybase.
- I have a public key ASBcBLvibntJ902rdW7l5CQsei6PPZZHJvMpNAmqRA91qwo
To claim this, I am signing this object:
enum NetworkFailureCode: Int { | |
case unknown = -1 | |
case cancelled = -999 | |
case badURL = -1000 | |
case timedOut = -1001 | |
case unsupportedURL = -1002 | |
case cannotFindHost = -1003 | |
case cannotConnectToHost = -1004 |
// MARK: - View Resizer when Keyboard Appears | |
extension UIViewController { | |
// This implementation was taken from: https://newfivefour.com/swift-ios-xcode-resizing-on-keyboard.html | |
// to improve the user experience the view updates will happen with the same animation as the keyboard's | |
func setupViewResizerOnKeyboardShown() { | |
NotificationCenter.default.addObserver(self, |
// | |
// TextContentType.swift | |
// textfield | |
// | |
// Created by Cassius Pacheco on 5/6/18. | |
// Copyright © 2018 Cassius Pacheco. All rights reserved. | |
// | |
import UIKit |
// | |
// TextContentType.swift | |
// textfield | |
// | |
// Created by Cassius Pacheco on 5/6/18. | |
// Copyright © 2018 Cassius Pacheco. All rights reserved. | |
// | |
import UIKit |
I hereby claim:
To claim this, I am signing this object:
// | |
import Foundation | |
import UIKit | |
public func associatedObject<ValueType: Any>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> ValueType) | |
-> ValueType { | |
// if there is already an associated value returns it | |
if let associated = objc_getAssociatedObject(base, key) as? ValueType { | |
return associated |
public func associatedObject<ValueType: Any>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> ValueType) | |
-> ValueType { | |
// if there is already an associated value returns it | |
if let associated = objc_getAssociatedObject(base, key) as? ValueType { | |
return associated | |
} | |
// associated value not found, initializes closure, makes the association and returns it | |
let associated = initializer() | |
associateObject(base: base, key: key, value: associated) |
import Foundation | |
import RxSwift | |
// Smart Retry idea originally from: http://kean.github.io/post/smart-retry | |
public enum DelayOptions { | |
case immediate | |
// Time is in milliseconds | |
case constant(time: Int) | |
// Initial is in milliseonds | |
case exponential(initial: Int, multiplier: Double) |
import Foundation | |
/// This property wrapper offers a locking mechanism for accessing/mutating values in a safer | |
/// way. Bear in mind that operations such as `+=` or executions of `if let` to read and then | |
/// mutate values are *unsafe*. Each time you access the variable to read it, it acquires the lock, | |
/// then once the read is finished it releases it. The following operation is to mutate the value, which | |
/// requires the lock to be mechanism again, however, another thread may have already claimed the lock | |
/// in between these two operations and have potentially changed the value. This may cause unexpected | |
/// results or crashes. | |
/// In order to ensure you've acquired the lock for a certain amount of time use the `mutate` method. |
// | |
import Foundation | |
extension NSLocking { | |
@discardableResult | |
public func sync<T>(action: () -> T) -> T { | |
lock() | |
defer { self.unlock() } |