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
// We reuse the above SportCarBuilder, we just change some interface | |
// Notice we instead are using the block for update the necessary properties | |
class SportCar { | |
typealias Builder = (builder: SportCarBuilder) -> Void | |
private init(builder: SportCarBuilder) { | |
super.init(doors: Door(2), engine: Engine(V85000), wheel: builder.wheel, color: builder.color) | |
} | |
static func make(with builderBlock: Builder) -> SportCar { |
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
// This one is a SportCarBuilder for building a sport car | |
// We just need two properties of wheel and color that can be added and modified | |
// However for engine and door has been defined by SportCar class | |
final class SportCarBuilder { | |
private var wheel: Wheel = Wheel(type: .racing(tyre20)) | |
private var color: Color = Color(.red) | |
func withColor(color: UIColor) { | |
self.color = Color(color) |
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
// This is the base Car class that has all of the foundation materials to make a Car | |
class Car { | |
let doors: Door | |
let wheel: Wheel | |
let engine: Engine | |
let color: Color | |
func buildCar() -> Car | |
} |
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
// | |
// NetworkKit.swift | |
// NetworkKitTutorial | |
// | |
// Created by Michael Abadi Santoso on 1/27/20. | |
// Copyright © 2020 Michael Abadi Santoso. All rights reserved. | |
// | |
import Foundation |
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
// | |
// StorageKit.swift | |
// StorageKitTutorial | |
// | |
// Created by Michael Abadi Santoso on 1/27/20. | |
// Copyright © 2020 Michael Abadi Santoso. All rights reserved. | |
// | |
import Foundation |
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
// | |
// SelectorEngine.swift | |
// SelectorUIViewKitTutorial | |
// | |
// Created by Michael Abadi Santoso on 1/27/20. | |
// Copyright © 2020 Michael Abadi Santoso. All rights reserved. | |
// | |
import Foundation | |
import SwiftUI |
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
// | |
// SelectorView.swift | |
// SelectorUIViewKitTutorial | |
// | |
// Created by Michael Abadi Santoso on 1/27/20. | |
// Copyright © 2020 Michael Abadi Santoso. All rights reserved. | |
// | |
import SwiftUI |