Git Product home page Git Product logo

movies's Introduction

iOS MVVM Exploration in Swift

This is my first attempt at applying the Model-View-ViewModel (MVVM) architectural pattern for iOS development:

  • The binding between the View and the ViewModel is done through the use of property observer didSet and closures.
  • Unlike most - if not all - of the MVVM tutorial projects out there, I create the View programmatically (no storyboard).

In this project, I also ...

  • parse JSON data from a local file all_movies.json
  • embed UICollectionView inside UITableView

Application Overview

iOS application that displays "movies" (you will know why after running the application) based on their categories / genres.

Code Structure Overview

While iOS MVVM architecture usually combines View and ViewController to be the View component of MVVM, I make a slight distinction between the two of them:

  • View takes care of the UI elements' appearances (attributes and layouts).
  • ViewController (Controller) acts as the data source and delegate to UITableView and UICollectionView.
  • ViewController (Controller) takes care of user interaction.
  • ViewController (Controller) has reference to both View and ViewModel.
  • View does not have reference to ViewController.

Reflection

The application includes UICollectionView that is embedded inside UITableView. Without storyboard, I need to set the height of the UITableView and UICollectionView programmatically through their respective delegate methods. This causes some problem when I attempt to bind UITableView and UICollectionView to their respective delegates and data sources (AllMoviesViewController) reactively using RxSwift.

While the data source and delegate binding is taken care of by RxSwift, .bind() method does not take into consideration the width and height of the UITableView and UICollectionView. Hence, I am not able to set the height of UITableView and UICollectionView. This is, however, not a problem if storyboard is used for the layouts of UI elements are specified there.

Even though I do experiment with RxSwift and RxCocoa a little bit in this project, I do not focus too much on them. I am sure that there is a way / workaround to solve this issue, but I will leave that research for another project.

Additional Note

The application UI is not iPhone X compatible because safeAreaLayoutGuide is not used when coding the UI elements layouts. It works fine with other iPhone and iPad simulators.

movies's People

Contributors

ct15 avatar

Stargazers

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

Watchers

 avatar

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.