Skip to content

Instantly share code, notes, and snippets.

View asobolevsky's full-sized avatar

Aleksei Sobolevskii asobolevsky

  • Le Poisson du Mars
  • Toronto, Canada
View GitHub Profile
extension UINavigationController {
override open var childForStatusBarStyle: UIViewController? {
return topViewController
}
}
extension UITabBarController {
override open var childForStatusBarStyle: UIViewController? {
return selectedViewController
}
extension UISplitViewController {
open override var childForStatusBarStyle: UIViewController? {
return viewControllers.first
}
}
extension UITabBarController {
open override var childForStatusBarStyle: UIViewController? {
return selectedViewController
}
extension UICollectionViewCell {
static let reuseID = String(describing: self)
static let nib = UINib(nibName: String(describing: self), bundle: nil)
}
final class PersistentStack {
private let storeUrl: URL
private let modelUrl: URL
private lazy var managedObjectModel: NSManagedObjectModel = {
guard let model = NSManagedObjectModel(contentsOf: modelUrl) else {
fatalError("Cannot find model file with URL: \(modelUrl)")
}
return model
enum CountryCode: String {
case us = "USA"
case zh = "China"
case fr = "France"
case ru = "Russia"
var locale: Locale {
let identifier: String
import UIKit
protocol CalendarDelegate: class {
func calendar(_ calendar: Calendar, willDisplay year: Int)
func calendar(_ calendar: Calendar, didSelect date: Date)
func calendarShouldChangeYear(_ calendar: Calendar) -> Bool
}
protocol CalendarDataSource {
func calendar(_ calendar: Calendar, eventsFor date: Date) -> [String]
import UIKit
typealias BehaviorClosure = (_ viewController: UIViewController) -> ()
protocol ViewControllerLifecycleBehavior {
func afterLoading(_ viewController: UIViewController)
func beforeAppearing(_ viewController: UIViewController)
func afterAppearing(_ viewController: UIViewController)
var ordersList: Order? {
didSet {
var fullLabelAddressFromAndStatusLabel = ""
var fullLabelAddressToAndStatusLabel = ""
var statusStringLengthFrom = 0
var statusStringLengthTo = 0
orderFirstTimeLabel.text = ""
orderSecondTimeLabel.text = ""
extension UIColor {
public convenience init?(hex: String) {
let r, g, b, a: CGFloat
if hex.hasPrefix("#") {
let start = hex.index(hex.startIndex, offsetBy: 1)
let hexColor = String(hex[start...])
if hexColor.count == 8 {
let scanner = Scanner(string: hexColor)
protocol ServiceLocating {
func getService<T>() -> T?
}
final class ServiceLocator: ServiceLocating {
private lazy var services: Dictionary<String, Any> = [:]
private func typeName(some: Any) -> String {
return (some is Any.Type) ?
"\(some)" : "\(type(of: some))"