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 { | |
var count: Int { | |
var length = 0 | |
enumerateSubstrings(in: startIndex..<endIndex, options: .byComposedCharacterSequences) { substring, substringRange, enclosingRange, stop in | |
length += 1 | |
} | |
return length | |
} | |
} |
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 Dictionary where Value == Any { | |
func value<T>(forKey key: Key, defaultValue: @autoclosure () -> T) -> T { | |
guard let value = self[key] as? T else { return defaultValue() } | |
return 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
protocol EnumStringConvertible: CustomStringConvertible {} | |
extension EnumStringConvertible { | |
var description: String { return String(reflecting: self) } | |
} | |
protocol EnumUserDefaultsConvertible: EnumStringConvertible {} | |
extension EnumUserDefaultsConvertible { | |
var key: String { return description } | |
var value: Any? { | |
get { return UserDefaults.standard[key] } |
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
private var targets = [Target]() | |
extension UIGestureRecognizer { | |
convenience init(action: @escaping (UIGestureRecognizer) -> ()) { | |
self.init() | |
addAction(action) | |
} | |
func addAction(_ action: @escaping (UIGestureRecognizer) -> ()) { |
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
func delay(_ seconds: Int, _ queue: DispatchQueue = .main, _ closure: @escaping () -> Void) { | |
let time = DispatchTime.now() + .seconds(seconds) | |
queue.asyncAfter(deadline: time, execute: closure) | |
} |
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
// preprocessor macros for logging | |
#define DefaultLog [NSString stringWithFormat:@"%s (line %d)", __PRETTY_FUNCTION__, __LINE__] | |
#define LogWarn(format, ...) NSLog((@"%@ -> WARNING: " format), DefaultLog, ##__VA_ARGS__) | |
#define LogError(format, ...) NSLog((@"%@ -> ERROR: " format), DefaultLog, ##__VA_ARGS__) |
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 Dictionary { | |
subscript(key: Key, `default` value: Value) -> Value { | |
mutating get { | |
return self[key] ?? { | |
self[key] = value | |
return value | |
}() | |
} | |
set { self[key] = 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 Typist | |
protocol KeyboardAware { | |
var keyboard: Typist { get } | |
var contentInset: UIEdgeInsets { get } | |
var scrollIndicatorInsets: UIEdgeInsets { get } | |
} | |
extension KeyboardAware where Self: UIScrollView { | |
func observeKeyboard() { |