Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Uma referência MVVM em um mundo MVC - 8ª CocoaHeads Fortaleza

Uma referência MVVM em um mundo MVC - 8ª CocoaHeads Fortaleza

Uma pequena introdução ao mundo MVVM trazendo a diferença da tecnologia para o padrão adotado pela Apple que é o MVC. Aborda projetos em MVVM e sua explanação de como funciona e também a rapidez em relação ao MVC.

More Decks by Vinicius Carvalho Marques

Other Decks in Technology

Transcript

  1. class Animal { var name: String var age: Int var

    image: UIImage init(name: String, age: Int, image: UIImage) { self.name = name self.age = age self.image = image } }
  2. A view é um objeto que normalmente representa um objeto

    de um modelo na interface do usuário. View Objects
  3. Mapeia a entrada do usuário em objetos do modelo, é

    notificado de alterações e atualiza a interface do usuário. Controller Objects
  4. class AnimalViewController: UIViewController { // Model Object var animal: Animal

    // View Object var imageView: UIImageView override func viewDidLoad() { // Maps Model into a View imageView.image = animal.image } }
  5. …MVC is the pattern of your choice if you are

    not ready to invest more time in your architecture, and you feel that something with higher maintenance cost is an overkill for your tiny pet project. — Bohdan Orlov
  6. class AnimalViewModel { let name: String let image: UIImage private

    let _hungry: Variable<Bool> var hungry: Observable<Bool> { return _hungry.asObservable() } init(animal: Animal) { name = animal.name image = animal.image _hungry = Variable(false) } }
  7. class AnimalTableViewCell: UITableViewCell { private var imageView: UIImageView private var

    nameLabel: UILabel private var hungryIconView: HungryIconView private let disposeBag = DisposeBag() var viewModel: AnimalViewModel { didSet { imageView.image = viewModel.image nameLabel.text = viewModel.name viewModel.hungry .bindNext { hungry in hungryIconView.hidden = !hungry }.addDisposableTo(disposeBag) } } }
  8. Reduzir a complexidade de suas view controllers e tornar a

    sua lógica mais fácil de ser testada!
  9. — MVVM is compatible with your existing MVC architecture.  — MVVM

    makes your apps more testable.  — MVVM works best with a binding mechanism. 
 
  Ash Furrow
  10. • Binary size • Bootup time • CPU usage (average

    and peaks) • Memory usage (average and peaks) • Main thread locks
  11. Escolha o melhor para você e seu projeto, não entre

    em modinhas! Existem diversos padrões, MVP, MV-X, VIPER, VIP…