This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let module = Module { | |
Single.init { _ in DatabaseClient()} | |
Factory.init {_ in MyViewModel()} | |
Single.init { _ in ApiClient()} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwDin | |
final class MyViewModel: SwDinViewModel { | |
// Called whenever this ViewModel will get attached to a ViewController | |
func onAttach() { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SwDin | |
class HomeViewController: UIViewController { | |
@InjectViewModel | |
private var viewModel: HomeViewModel | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwDin | |
final class HomeViewModel: SwDinViewModel { | |
@Inject | |
private let dbClient: DatabaseClient | |
@Inject | |
private let apiClient: ApiClient | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class FirstViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// When we want to goto the SecondViewController. | |
let repository = SomeRepository() | |
let service = SomeService() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github "OhhhThatVarun/SwDin" ~> 1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
OlderNewer