Code Monkey home page Code Monkey logo

ios-architecture's Introduction

ios-architecture

WIP

๐Ÿ‘ท ๐Ÿงฑ ๐Ÿงฐ ๐Ÿ› ๏ธ
Demystifying MVC, MVVM, VIPER, RIBs and many others
A collection of simple one screen apps to showcase and discuss different architectural approaches in iOS

last commit open issues swift version platform license
Built with โค๏ธŽ by Pawel Krawiec


Apps

Multi-screen examples Single screen examples
app-ui app-ui

Architectures

This repository hosts each sample app in separate directory.

โญ Click the title of example to see detailed README information about specific architecture.

Multiple screens app examples

๐Ÿ”’ ** If you want to login, use username iostest and password test.**

If you're a themoviedb user, please use your own account and API key!

Example Description
tmdb-mvvm-rxswift-pure Uses RxSwift and observables as binding mechanism between ViewController and ViewModel. Also, it uses simple navigator pattern for transitions between screens. (README in progress)

Single screen app examples

The purpose of having examples with single page applications is highlighting connection between view code and business logic code.

Example Description
mvc Standard MVC pattern recommended by Apple. Uses composition design pattern to make ViewController smaller. (README in progress)
mvp Standard MVP pattern. (README in progress)
mvvm-rxswift-pure Uses RxSwift and observables as binding mechanism between ViewController and ViewModel.
mvvm-rxswift-functions-subjects-observables Uses RxSwift and observables as outputs from ViewModel. ViewModel inputs are defined as subjects wrapped in functions.
mvvm-rxswift-subjects-observables Uses RxSwift with observables as ViewModel outputs and subjects as ViewModel inputs.
mvvm-closures Binds ViewController and ViewModel using closures and swift functions (README in progress)
rxfeedback-mvc Uses RxFeedback in MVC architecture (README in progress)
viper Uses VIPER architecture (README in progress)

Examples in progress

Example Description
reactorkit In Progress
mvvm+rxfeedback In Progress
mvvm-reactive-swift In Progress
reswift In Progress
viper-rxswift In Progress
ribs In Progress

Sample apps

Apps in this repository are split into 2 groups - single screen and multiscreen.

Simple one screen apps aim to be simple enough that you can understand crucial bits about given architecture (i.e. bindings between ViewModel and ViewController in MVVM examples). However, some other architectures require more complexity (i.e. RIBs architecture) and this is the reason of having multiscreen examples in this project.

Single screen app

Single screen app is a simple list of repositories fetched from GitHub and a text field that makes queries for new data.

Multiscreen app

Multiscreen app is a simple themoviedb client. It lets user to authenticate, view popular movies/tv shows or actors and see details about each movie. Also, it has a search screen that allows you to browse movies or actors.

Open in Xcode

Clone the repository:

git clone [email protected]:tailec/ios-architecture.git

Go to example directory, for example:

cd mvvm-pure-swift

Install pods:

pod install

Note: Some of the examples don't use external libraries so pod install is not required.

Licence

MIT.

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  avatar

ios-architecture's Issues

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?

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
    }
}

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.