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 AnimalReport { | |
func describe(_ animal: Animal) { | |
print("Animal is called \(animal.name) and is \(animal.age) years old") | |
} | |
} | |
struct AnimalSelection { | |
let animals: [Animal] | |
let animalReport: AnimalReport | |
func selectAnimal(_ animal: Animal) { |
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 AnimalContext { | |
var selectedAnimal: Animal? | |
} | |
struct AnimalReport { | |
let animalContext: AnimalContext | |
func describe() { | |
guard let animal = animalContext.selectedAnimal else { return } | |
print("Animal is called \(animal.name) and is \(animal.age) years old") | |
} |
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 AnimalReportFactory { | |
func makeAnimalReport(for animal: Animal) -> AnimalReport { | |
AnimalReport(animal: animal) | |
} | |
} | |
struct AnimalReport { | |
let animal: Animal | |
func describe() { | |
print("Animal is called \(animal.name) and is \(animal.age) years old") |
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 AnimalSelection { | |
let animals: [Animal] | |
func selectAnimal(_ animal: Animal) { | |
let animalReport = Container.resolve(AnimalReport.self, argument: animal) | |
animalReport.describe() | |
} | |
} |
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
protocol AnimalReportLocatorProtocol { | |
func animalReport(for animal: Animal) -> AnimalReport | |
} | |
extension Container: AnimalReportLocatorProtocol { | |
func animalReport(for animal: Animal) -> AnimalReport { | |
container.resolve(AnimalReport.self, argument: animal) | |
} | |
} |
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
// How connecting constraints was before: | |
let myView = UIView() | |
myView.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(myView) | |
myView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true | |
myView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true | |
myView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true | |
myView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true | |
// Now you have different ways of connecting them: |
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
// | |
// CreditCardFormatter.swift | |
// | |
// Created by Eduardo Domene Junior on 31.05.21. | |
// | |
import Foundation | |
class CreditCardFormatter: MaskedFormatter { | |
init() { |
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
import UIKit | |
import PlaygroundSupport | |
class ClientViewController: UIViewController { | |
private lazy var content: UIView = { | |
quarterNote | |
}() | |
private let quarterNote: UILabel = { |
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 MusicSheetPlotter { | |
let quarterNote: UILabel | |
func plot(in view: UIView) { | |
let stack = UIStackView() | |
stack.axis = .horizontal | |
stack.distribution = .equalSpacing | |
stack.spacing = 5.0 | |
stack.addArrangedSubview(quarterNote) |
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
// ClientViewController | |
... | |
private lazy var content: UIView = { | |
let view = UIView() | |
view.translatesAutoresizingMaskIntoConstraints = false | |
let plotter = MusicSheetPlotter(quarterNote: quarterNote) | |
plotter.plot(in: view) | |
return view |