Code Monkey home page Code Monkey logo

ios-architecture's People

Contributors

amadeu01 avatar tailec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios-architecture's Issues

mvvm-delegates is not MVVM, actually that is MVP.

Hi, @tailec

ViewModel has a reference of abstracted ViewController as Delegate in mvvm-delegation.
It means that is not MVVM, actually that is MVP.
@amadeu01 mentioned in #2 (comment) , too.

I have a doubt about #2 (comment) .

I think in MVP, presenter can have access to view (imports UIKit) but view models in MVVM are forbidden to do that.

I think differences between MVP and MVVM are those have references of View directly or not.

Presenter in MVP

Presenter has a reference of View (or ViewController) that is abstracted as protocol in almost cases.
To reflect state of Presenter, it calls method of abstructed View.

protocol CounterView {
    func didChangeCount(_ presenter: CounterPresenter, count: Int)
}

class CounterViewController: UIViewController, CounterView {
    let presenter: CounterPresenter
    let countLabel: UILabel

    override func viewDidLoad() {
        super.viewDidLoad()

        presenter.view = self
    }

    func countUp() {
        presenter.countUp()
    }
}

extension CounterViewController: CounterView {
    func didChangeCount(_ presenter: CounterPresenter, count: Int) {
        countLabel?.text = "\(count)"
    }
}

class CounterPresenter {
    private(set) var count: Int = 0 {
        didSet {
             view?.didChangeCount(self, count: count)
        }
    }

    weak var view: CounterView?

    func countUp() {
        count += 1
    }
}

ViewModel in MVVM

ViewModel must not depend on View (or ViewController).
Even if View is abstracted as Protocol, ViewModel must not depend on them.
To reflect state of ViewModel, it notifies changes of state with closure (or RxSwift.Observable and so on).
Closure is implemented outside of ViewModel, therefore ViewModel does not depend on View directly.

class CounterViewController: UIViewController {
    let viewModel: CounterViewModel
    let countLabel: UILabel

    override func viewDidLoad() {
        super.viewDidLoad()

        viewModel.countChanged = { [weak countLabel] count in
            countLabel?.text = "\(count)"
        }
    }

    func countUp() {
        viewModel.countUp()
    }
}

class CounterViewModel {
    private(set) var count: Int = 0 {
        didSet {
             countChanged?(count)
        }
    }

    var countChanged: ((Int) -> Void)?

    func countUp() {
        count += 1
    }
}

Error when Building after install/ update pods

Hi,
I have problem when I want to build the RXswift project in this Repository. I had cloned this repository and installed / updated the pods. When I build the project, those are some error occurred.
The error is: Static member 'load' cannot be used on instance of type 'AtomicInt'
What should I do to fix the error?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.