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
let url = URL() | |
_ = UIImageView.af_sharedImageDownloader.imageCache?.removeImage(for: URLRequest(url: url), withIdentifier: nil) | |
imageView.af_setImage(withURL: url) |
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 | |
class NotificationManager { | |
private var tokens = [String: AnyObject]() | |
deinit { | |
tokens.values.forEach { NC.removeObserver($0) } | |
} | |
func addObserver(forName name: NSNotification.Name, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) { |
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 Constrainable {} | |
extension Constrainable where Self: UIView { | |
@discardableResult | |
func constrain(constraints: (Self) -> [NSLayoutConstraint]) -> [NSLayoutConstraint] { | |
let constraints = constraints(self) | |
self.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate(constraints) | |
return constraints |
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 | |
private class Associated<Type>: NSObject { | |
let value: Type | |
init(_ value: Type) { | |
self.value = value | |
} | |
} | |
protocol Associable {} |
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 UIFont { | |
func bold() -> UIFont? { | |
return fontDescriptor.withSymbolicTraits(.traitBold).map { UIFont(descriptor: $0, size: 0) } | |
} | |
} |
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 SearchResultProtocol: Hashable, Equatable { | |
var name: String { get } | |
} | |
extension SearchResultProtocol { | |
var hashValue: Int { | |
return name.hashValue | |
} | |
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 struct Stack<U> { | |
typealias T = (stack: [[U]], current: [U]) | |
private var value: T | |
var values: [[U]] { | |
return value.stack + [value.current] | |
} | |
init() { | |
self.value = (stack: [], current: []) | |
} | |
mutating func add(toStack element: U) { |
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 SomeView: UIKeyInput { | |
var hasText: Bool { return true } | |
func insertText(_ text: String) {} | |
func deleteBackward() {} | |
override var canBecomeFirstResponder: Bool { return true } | |
} |
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 MKMapRect { | |
init(minX: Double, minY: Double, maxX: Double, maxY: Double) { | |
self.init(x: minX, y: minY, width: abs(maxX - minX), height: abs(maxY - minY)) | |
} | |
init(x: Double, y: Double, width: Double, height: Double) { | |
self.init(origin: MKMapPoint(x: x, y: y), size: MKMapSize(width: width, height: height)) | |
} | |
var minX: Double { return MKMapRectGetMinX(self) } | |
var minY: Double { return MKMapRectGetMinY(self) } | |
var midX: Double { return MKMapRectGetMidX(self) } |
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 RealmSwift | |
protocol ObjectProtocol {} | |
extension ObjectProtocol where Self: Object { | |
static func objects() -> Results<Self> { | |
return try! Realm().objects(self) | |
} | |
static func object(_ primaryKey: Any) -> Self? { | |
return try! Realm().object(ofType: self, forPrimaryKey: primaryKey) |