Skip to content

Instantly share code, notes, and snippets.

View VladimirBrejcha's full-sized avatar
🎯
Focusing

Vladimir Korolev VladimirBrejcha

🎯
Focusing
View GitHub Profile
//
// ExtensionURLRequest.swift
//
// Created by Abhishek Maurya on 16/07/20.
// Copyright © 2020. All rights reserved.
//
import Foundation
extension URLRequest {
import Foundation
class Debounce {
private let queue: DispatchQueue
private let delay: Double
private var workItem: DispatchWorkItem?
private var cancelBlock: (() -> Void)?
init(queue: DispatchQueue, delay: Double) {
self.queue = queue
import Foundation
class Throttle {
private let queue: DispatchQueue
private let delay: Double
private var delayedBlock: (() -> Void)?
private var cancelBlock: (() -> Void)?
private var timer: DispatchSourceTimer?
private var isReady = true
private var hasDelayedBlock: Bool { delayedBlock != nil }
import UIKit
extension UIStoryboard {
func instantiateViewController<Type: UIViewController>(of type: Type.Type) -> Type {
instantiateViewController(withIdentifier: String(describing: type)) as! Type
}
}
@VladimirBrejcha
VladimirBrejcha / NibLoadable.swift
Created August 1, 2020 12:32
simplify loading views from nib file
import UIKit
protocol NibLoadable where Self: UIView {
static var nibName: String { get }
}
extension NibLoadable {
static var nibName: String { String(describing: Self.self) }
static var nib: UINib { UINib(nibName: Self.nibName, bundle: Bundle(for: Self.self)) }
import Foundation
fileprivate let userDefaults = UserDefaults.standart
fileprivate let userDefaultsDomain = Bundle.main.bundleIdentifier ?? ""
fileprivate extension String {
var appendingAppDomain: String {
"\(userDefaultsDomain).\(self)"
}
}
@VladimirBrejcha
VladimirBrejcha / AutoRefreshable.swift
Last active August 1, 2020 19:23
AutoRefreshable.swift
import Foundation
protocol Refreshable {
associatedtype DataType
func refresh(with data: DataType)
}
protocol AutoRefreshable: AnyObject, Refreshable {
var timer: Timer? { get set }
var dataSource: (() -> DataType)? { get set }