Skip to content

Instantly share code, notes, and snippets.

View OhhhThatVarun's full-sized avatar
🎯
Focusing

Varun Raj OhhhThatVarun

🎯
Focusing
View GitHub Profile
@OhhhThatVarun
OhhhThatVarun / TraditonalVerification.kt
Created July 13, 2021 09:23
Demonstrating a traditional way to validate user input.
fun validateUserInput(): Boolean {
val emailPattern = Pattern.compile("my-perfect-regex")
val passwordPattern = Pattern.compile("my-perfect-regex")
if(email == null || email.length > 30 || !emailPattern.matcher(email).matches()) {
// Handle Email is invalid
} else if (password == null || password.length > 30 || !passwordPattern.matcher(password).matches()) {
// Handle Password is invalid
} else {
@OhhhThatVarun
OhhhThatVarun / Carthage Version
Created March 19, 2021 13:48
SwDin: Latest Carthage version
github "OhhhThatVarun/SwDin" ~> 1.0.0
@OhhhThatVarun
OhhhThatVarun / Cocoapod Version.pod
Created March 19, 2021 13:45
SwDin: Latest CocoaPod version
pod 'SwDin', '~> 1.0.0'
@OhhhThatVarun
OhhhThatVarun / LodingSwDinModules.swift
Created March 16, 2021 14:08
SwDin: Loading modules.
import SwDin
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
SwDin.start(modules: [module])
// or SwDin.start(modules: [module], attachLogger: true)
}
@OhhhThatVarun
OhhhThatVarun / Injectables.swift
Created March 16, 2021 13:39
SwDin: Single and Factory demonstration.
// Using Single here because requirement is the same instance of the DatabaseClient on every @Inject.
let injectable = Single.init { _ in DatabaseClient()}
// Using Factory here becuase requirement is a new instance of MyViewModel on every @InjectViewModel.
let injectable = Factory.init {_ in MyViewModel()}
@OhhhThatVarun
OhhhThatVarun / ConstructorInjection.swift
Created March 16, 2021 13:17
SwDin: Simple constructor Injection example.
import UIKit
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// When we want to goto the SecondViewController.
let repository = SomeRepository()
let service = SomeService()
@OhhhThatVarun
OhhhThatVarun / HomeViewModel.swift
Last active March 16, 2021 11:26
SwDin: ViewModel inject example.
import SwDin
final class HomeViewModel: SwDinViewModel {
@Inject
private let dbClient: DatabaseClient
@Inject
private let apiClient: ApiClient
@OhhhThatVarun
OhhhThatVarun / InjectExaample.swift
Created March 16, 2021 11:18
SwDin: ViewModel Injection example.
import UIKit
import SwDin
class HomeViewController: UIViewController {
@InjectViewModel
private var viewModel: HomeViewModel
override func viewDidLoad() {
super.viewDidLoad()
@OhhhThatVarun
OhhhThatVarun / SwDinMyViewModel.swift
Created March 16, 2021 11:12
SwDinViewModel usage.
import SwDin
final class MyViewModel: SwDinViewModel {
// Called whenever this ViewModel will get attached to a ViewController
func onAttach() {
}
}
@OhhhThatVarun
OhhhThatVarun / SwDinModule.swift
Last active March 16, 2021 09:48
Declaring a module in SwDin
let module = Module {
Single.init { _ in DatabaseClient()}
Factory.init {_ in MyViewModel()}
Single.init { _ in ApiClient()}
}