• Stars
    star
    183
  • Rank 210,154 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 5 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample iOS application in Swift presenting MVVM-C architecture

BuyMeACoffee

Swift-MVVMC-Demo

Sample iOS application in Swift presenting usage of MVVM-C pattern.

If you want to check out just a simple MVVM-C pattern without extra features, please see this repository: Swift-MVVMC-SimpleExample

Application Features

  • Sign in screen
  • Dashboard with sample data fetched from mocked backend
  • Onboarding displayed after login
  • Settings stored locally
  • Drawer menu with: dashboard, settings, sing out

Implementation features

  • Dendency Injection using Swinject
  • Session management
  • Translations fetched from backend
  • UI controls with settable translations on Storyboard
  • Api endpoints defined in OOP manner by subclassing BaseApiRequest<T>
  • Logging

Architecture

This project is POC for MVVM-C pattern where:

  • View is represented by UIViewController designed in Storyboard
  • Model represents state and domain objects
  • ViewModel interacts with Model and prepares data to be displayed. View uses ViewModel's data either directly or through bindings (using RxSwift) to configure itself. View also notifies ViewModel about user actions like button tap.
  • Coordinator is responsible for handling application flow, decides when and where to go based on events from ViewModel (using RxSwift bindings).

View <- ViewController <- bindings -> (ViewModel -> Model) <- bindings -> Coordinator

Coordinators hierarchy

Pros

  • View doesn't contain logic, it just configures itself based on ViewModel.
  • ViewModel is UIKit independent and fully testable. Thanks to communication through RxSwift it doesn't know about Coordinator nor about View.
  • Views and ViewModels are reusable because they are indepdent and doesn't contain knowledge about application's flow.
  • Coordinator is able to handle passing data between ViewModels.

Cons

  • Each screen requires a lot of boilerplate. You need to create Coordinator, ViewController, ViewModel and bind all together.
  • RxSwift is quite tricky if you are not careful enough. It's easy to cause memory leak, that's why you have to invest more time in debugging.
  • Bindings are not supported natively (unlike in Xamarin.Forms), therefore it is required to write a lot of "binding code" each time even when using RxSwift.
  • RxSwift may become hard in debugging once code complexity increases.

Compilation

Project uses CocoaPods for dependencies, so install it first and then run:

pod install

Application usage

Sample login screen accepts any e-mail address and password pass.

References

You can also check out my another demo with Redux architecture:

More Repositories

1

xcodebuild.nvim

Neovim plugin to Build, Debug, and Test applications created for Apple devices (iOS, macOS, watchOS, etc.)
Lua
410
star
2

SwiftUI-Redux-Demo

SwiftUI application presenting Redux architecture and its mindblowing possibilities
Swift
55
star
3

ios-dev-starter-nvim

Bootstrap for iOS development in Neovim + LazyVim
Lua
52
star
4

Swift-MVVMC-SimpleExample

Simple example of MVVM pattern and MVVM with Coordinators
Swift
49
star
5

WidgetKit-Demo

Sample iOS project with iOS 14 widgets
Swift
21
star
6

SwiftBluetooth

Implementation of Bluetooth Low Energy communication using Flow Controllers to make asynchronous code clean
Swift
19
star
7

Sample-Projects

This repository contains my sample projects in C# for Windows Desktop and Windows Phone.
C#
16
star
8

Library-Manager

Simple desktop application written in C# (WPF) to manage a library.
C#
12
star
9

NugetAcknowledgementExporter

Exports automatically acknowledgements for all Nuget Packages included in .NET projects
C#
7
star
10

iCloud-Demo

Sample iOS project showing how to implement and use iCloud services.
Swift
7
star
11

CoreDataVsRealm

Sample usage of Core Data and Realm
Swift
6
star
12

RxBluetoothDemo

RxBluetoothKit pairing demo
Swift
6
star
13

ILTools

Simple Common Intermediate Language (IL) structure parser + viewer + obfuscator
C#
3
star
14

WKFramework

Small framework written in C#. Still working on it, so for now only settings, navigation and some utils are available.
C#
3
star
15

ReSwiftDemo

Swift
2
star
16

Algorithms

Repository contains my implementations of some algorithms and data structures.
C++
2
star
17

SPM-Sharing-Dependencies

This repository shows how to share dependencies between modules
Swift
1
star
18

Swift-RTFD-Bug

This bug shows an inconsistency in RTFD serialization.
1
star
19

DanceFloor

This game has been created to practice C# WPF. It's a simplified version of StepMania.
C#
1
star
20

Swift-Crazy-iBugs

Set of crazy bugs that I discovered on iOS, iPadOS, and macOS.
Swift
1
star