Skip to content

Instantly share code, notes, and snippets.

View efremidze's full-sized avatar
👨‍💻

Lasha Efremidze efremidze

👨‍💻
View GitHub Profile
import UIKit
import AVFoundation
class ResizingImageView: UIImageView {
private var heightConstraint: NSLayoutConstraint?
override var image: UIImage? {
didSet {
_ = heightConstraint.map { NSLayoutConstraint.deactivate([$0]) }
class Messenger {
func log(_ message: String) {
print(message)
}
func logThis() {
DispatchQueue.main.async { [weak self] in
guard let this = self else { return }
this.log("1")
import UIKit
class InsetLabel: UILabel {
var insets = UIEdgeInsets()
override var intrinsicContentSize: CGSize {
var size = super.intrinsicContentSize
size.width += insets.left + insets.right
size.height += insets.top + insets.bottom
import Foundation
private class Associated<Type>: NSObject {
let value: Type
init(_ value: Type) {
self.value = value
}
}
protocol Associable {}
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
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) {
let url = URL()
_ = UIImageView.af_sharedImageDownloader.imageCache?.removeImage(for: URLRequest(url: url), withIdentifier: nil)
imageView.af_setImage(withURL: url)
import Foundation
typealias Points = Int
extension Points {
func rank() -> Rank {
return Rank(self)
}
}
private let swizzling: (AnyClass, Selector, Selector) -> () = { forClass, originalSelector, swizzledSelector in
let originalMethod = class_getInstanceMethod(forClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector)
method_exchangeImplementations(originalMethod, swizzledMethod)
}
extension UIView {
open override class func initialize() {
// make sure this isn't a subclass
enum AppStoryboard: String {
case Main
var instance: UIStoryboard {
return UIStoryboard(name: rawValue, bundle: Bundle.main)
}
func viewController<T: UIViewController>(of type: T.Type) -> T {
return instance.instantiateViewController(withIdentifier: type.storyboardId) as! T
}