This file contains hidden or 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
// In a class that wants an instance of RGBColourViewModel | |
extension RGBColourViewController: Resolving { | |
func makeViewModel(input: RGBColourViewModel.Input) -> RGBColourViewModel { | |
Resolver.resolve(args: input) | |
} | |
} |
This file contains hidden or 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
// In our +Injection.swift file | |
extension Resolver: ResolverRegistering { | |
public static func registerAllServices() { | |
register { _, args in | |
RGBColourViewModel(input: args(), colourTransformService: resolve()) | |
} | |
} | |
} |
This file contains hidden or 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
class RGBColourViewModel { | |
init(input: Input, colourTransformService: ColourTransformService) { | |
// setup logic | |
} | |
} |
This file contains hidden or 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
class RGBColourViewController: UIViewController { | |
let rgbColourView = RGBColourView() | |
let disposeBag = DisposeBag() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Create the view model and provide the input observables | |
let viewModel = RGBColourViewModel( | |
input: RGBColourViewModel.Input( |
This file contains hidden or 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
private func transform(redString: String?, greenString: String?, blueString: String?) -> UIColor { | |
guard let redString = redString, | |
let greenString = greenString, | |
let blueString = blueString else { | |
return .black | |
} | |
guard let red = Double(redString), | |
let green = Double(greenString), | |
let blue = Double(blueString) else { |
This file contains hidden or 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
class RGBColourViewModel { | |
private let input: Input | |
lazy var output: Output = { | |
createOutput() | |
}() | |
init(input: Input) { | |
self.input = input | |
} | |
This file contains hidden or 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
struct Output { | |
let colour: Driver<UIColor> | |
} |
This file contains hidden or 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
struct Input { | |
let red: Observable<String?> | |
let green: Observable<String?> | |
let blue: Observable<String?> | |
} |