This file contains 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 | |
extension Character { | |
var byte: UInt8 { | |
return String(self).utf8.map{UInt8($0)}[0] | |
} | |
var short: UInt16 { | |
return String(self).utf16.map{UInt16($0)}[0] | |
} |
This file contains 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 UIViewController { | |
func changeRootViewController(to viewController: UIViewController, animated: Bool, completion: (() -> Void)?) { | |
let toVC = viewController | |
let snapshot = UIApplication.shared.keyWindow!.snapshotView(afterScreenUpdates: true)! | |
let rootViewControllerChangeBlock = { | |
toVC.view.addSubview(snapshot) | |
UIApplication.shared.keyWindow?.rootViewController = toVC | |
let duration = animated ? 0.3 : 0 |
This file contains 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 UITableView { | |
func reloadDataAnimated() { | |
UIView.transition(with: self, | |
duration: 0.35, | |
options: .transitionCrossDissolve, | |
animations: { | |
self.reloadData() | |
}) | |
} |
This file contains 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
#if !swift(>=4.2) | |
public protocol CaseIterable { | |
associatedtype AllCases: Collection where AllCases.Element == Self | |
static var allCases: AllCases { get } | |
} | |
extension CaseIterable where Self: Hashable { | |
static var allCases: [Self] { | |
return [Self](AnySequence { () -> AnyIterator<Self> in | |
var raw = 0 |
This file contains 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
// Original: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24 | |
import Foundation | |
private struct JSONCodingKeys: CodingKey { | |
var stringValue: String | |
init(stringValue: String) { | |
self.stringValue = stringValue | |
} | |
This file contains 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
#!/usr/bin/env bash | |
rm -rf "${HOME}/Library/Caches/CocoaPods" | |
rm -rf "`pwd`/Pods/" | |
pod update | |
# In case a corrupt repo compromises `pod repo update` command | |
rm -rf ~/.cocoapods/repos |
This file contains 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 UserDefaults { | |
/// Sets the codable value of the specified key. | |
func set<Element: Codable>(_ value: Element, forKey key: String) { | |
let data = try? JSONEncoder().encode(value) | |
UserDefaults.standard.setValue(data, forKey: key) | |
} | |
/// Returns the codable value associated with the specified key. | |
func codable<Element: Codable>(forKey key: String) -> Element? { | |
guard let data = UserDefaults.standard.data(forKey: key) else { return nil } |