Skip to content

Instantly share code, notes, and snippets.

Avatar

Vadim Bulavin V8tr

View GitHub Profile
View currencies.json
[
{
"currencyCode": "AUD",
"country": "Australia",
"currencyName": "Australian Dollar",
"countryCode": "AU"
},
{
"currencyCode": "BGN",
"country": "Bulgaria",
View ViewStyle.swift
import Foundation
import UIKit
struct ViewStyle<T> {
let style: (T) -> Void
}
let filled = ViewStyle<UIButton> {
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .red
@V8tr
V8tr / AutoLayoutDSL.swift
Last active Aug 30, 2021
Auto Layout DSL
View AutoLayoutDSL.swift
import UIKit
/// Represents a single `NSLayoutConstraint`
enum LayoutAnchor {
case constant(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
constant: CGFloat)
case relative(attribute: NSLayoutConstraint.Attribute,
relation: NSLayoutConstraint.Relation,
@V8tr
V8tr / git-tips-and-tricks.md
Last active Apr 15, 2019
Git tips & tricks
View git-tips-and-tricks.md
@V8tr
V8tr / RefactoringAppDelegate-Composite.swift
Last active Aug 3, 2018
Refactoring Massive App Delegate using Composite pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
View RefactoringAppDelegate-Composite.swift
enum AppDelegateFactory {
static func makeDefault() -> AppDelegateType {
return CompositeAppDelegate(appDelegates: [PushNotificationsAppDelegate(), StartupConfiguratorAppDelegate(), ThirdPartiesConfiguratorAppDelegate()])
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
@V8tr
V8tr / RefactoringAppDelegate-Composite.swift
Last active Jun 13, 2021
Refactoring Massive App Delegate using Composite pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
View RefactoringAppDelegate-Composite.swift
class PushNotificationsAppDelegate: AppDelegateType {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Registered successfully
}
}
class StartupConfiguratorAppDelegate: AppDelegateType {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Perform startup configurations, e.g. build UI stack, setup UIApperance
return true
@V8tr
V8tr / RefactoringAppDelegate-Composite.swift
Last active Aug 3, 2018
Refactoring Massive App Delegate using Mediator pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
View RefactoringAppDelegate-Composite.swift
typealias AppDelegateType = UIResponder & UIApplicationDelegate
class CompositeAppDelegate: AppDelegateType {
private let appDelegates: [AppDelegateType]
init(appDelegates: [AppDelegateType]) {
self.appDelegates = appDelegates
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
@V8tr
V8tr / RefactoringAppDelegate-Mediator.swift
Created Aug 2, 2018
Refactoring Massive App Delegate using Mediator pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
View RefactoringAppDelegate-Mediator.swift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let mediator = AppLifecycleMediator.makeDefaultMediator()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
}
@V8tr
V8tr / RefactoringAppDelegate-Mediator.swift
Last active Aug 2, 2018
Refactoring Massive App Delegate using Mediator pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
View RefactoringAppDelegate-Mediator.swift
// MARK: - AppLifecycleListener
protocol AppLifecycleListener {
func onAppWillEnterForeground()
func onAppDidEnterBackground()
func onAppDidFinishLaunching()
}
// MARK: - Mediator
@V8tr
V8tr / RefactoringAppDelegate-Command.swift
Last active Aug 3, 2018
Refactoring Massive App Delegate using Command pattern. See blog post for more details: https://www.vadimbulavin.com/refactoring-massive-app-delegate
View RefactoringAppDelegate-Command.swift
// MARK: - Builder
final class StartupCommandsBuilder {
private var window: UIWindow!
func setKeyWindow(_ window: UIWindow) -> StartupCommandsBuilder {
self.window = window
return self
}