All Projects → danielt1263 → Rxearthquake

danielt1263 / Rxearthquake

Licence: mit
A sample app describing my philosophy on how to write iOS code with RxSwift.

Programming Languages

swift
15916 projects
declarative
70 projects

Labels

Projects that are alternatives of or similar to Rxearthquake

Rxlifecycle
🐹 Easy life cycle observation
Stars: ✭ 46 (-54.9%)
Mutual labels:  rxswift
Loginwithrxswift
A demo with Sign up and Login function With RxSwift
Stars: ✭ 63 (-38.24%)
Mutual labels:  rxswift
Rxkeyboard
Reactive Keyboard in iOS
Stars: ✭ 1,246 (+1121.57%)
Mutual labels:  rxswift
Ios
A sample project demonstrating MVVM, RxSwift, Coordinator Pattern, Dependency Injection
Stars: ✭ 49 (-51.96%)
Mutual labels:  rxswift
Rxswift Chinese Documentation
RxSwift 中文文档
Stars: ✭ 1,107 (+985.29%)
Mutual labels:  rxswift
Simpleapiclient Ios
A configurable api client based on Alamofire4 and RxSwift4 for iOS
Stars: ✭ 68 (-33.33%)
Mutual labels:  rxswift
Papr
🌁 An Unsplash app for iOS
Stars: ✭ 1,025 (+904.9%)
Mutual labels:  rxswift
Rxstorekit
StoreKit library for RxSwift
Stars: ✭ 96 (-5.88%)
Mutual labels:  rxswift
Jetchat
 Swift5.0编写的简仿微信聊天应用,完美支持表情键盘、单聊、群聊、本地消息会话缓存。
Stars: ✭ 61 (-40.2%)
Mutual labels:  rxswift
Rxbluetoothkit
iOS & OSX Bluetooth library for RxSwift
Stars: ✭ 1,213 (+1089.22%)
Mutual labels:  rxswift
Mvvm C with swift
Sample project using MVVM-C with Swift
Stars: ✭ 53 (-48.04%)
Mutual labels:  rxswift
Rxswiftext
A collection of Rx operators & tools not found in the core RxSwift distribution
Stars: ✭ 1,080 (+958.82%)
Mutual labels:  rxswift
Rxtodo
iOS Todo Application using RxSwift and ReactorKit
Stars: ✭ 1,186 (+1062.75%)
Mutual labels:  rxswift
Rxswift To Combine Cheatsheet
RxSwift to Apple’s Combine Cheat Sheet
Stars: ✭ 1,040 (+919.61%)
Mutual labels:  rxswift
Rxmarvel
Playing around marvel public API with RxSwift, Argo, Alamofire
Stars: ✭ 86 (-15.69%)
Mutual labels:  rxswift
Mvvmc Splitviewcontroller
Example project with UITabBarController inside UISplitViewController using RxSwift and MVVM-C architecture.
Stars: ✭ 45 (-55.88%)
Mutual labels:  rxswift
Rxexamples
Tests with RxSwift by book of Ray Wenderlich
Stars: ✭ 66 (-35.29%)
Mutual labels:  rxswift
Rerxswift
ReRxSwift: RxSwift bindings for ReSwift
Stars: ✭ 97 (-4.9%)
Mutual labels:  rxswift
Qiitawithfluxsample
A sample project uses Flux and MVVM features with RxSwift.
Stars: ✭ 94 (-7.84%)
Mutual labels:  rxswift
Cleverbot
iOS Messaging Application using Cleverbot and ReactorKit
Stars: ✭ 74 (-27.45%)
Mutual labels:  rxswift

RxEarthquake

This repository exists to demonstrate my technique and philosophy when building a project using the ReactiveX RxSwift library. Key ideas include:

  1. View controllers are isolated and know nothing of their parent or sibling view controllers. This promotes reuse and easy modification.
  2. The code base is written using a Cause-Logic-Effect Architecture.
  3. The resulting code is highly declarative style with a strong separation between logic and effects which help in understanding.

I find these values so useful that I aim to provide them even when not using a FRP library like RxSwift, but using such a library makes writing such code easier.

Isolate View Controllers

In a program written in the typical MVC style, every view controller knows how it was displayed, whether it has been presented or pushed onto a navigation stack, and knows about the next view controller(s) that will be shown to the user. In some code bases, it will even create and then tell it's parent to display its siblings. Such code distributes the display order into every part of the system. This makes it hard to reuse view controllers in different contexts and re-ordering the presentation flow of a series of view controllers requires carefully adjusting multiple classes.

In this sample program, the Coordinator is in charge of the navigation flow. It determines when and how view controllers are displayed and removed. I expect to need one Coordinator class for every split view, navigation, or other container controller in the system and that coordinator is in charge of displaying the contents of that container controller. In this particular case, despite there being two navigation controllers, the split view controller is in charge of what they display so I ended up with only one coordinator. If view controllers were getting pushed onto either navigation controller, then another coordinator would be required.

Cause-Logic-Effect Architecture

An effect is any side effect, a network request, changing the state of a view, saving to a DB, notifying an external system of some event, etc. Once you have an effect in mind, then you outline the causes (events) that cause that effect to happen, the result of a network request, a user action, a notification from some external system, etc. There are often several causes that all contribute to a single effect... Then you create a function that maps the cause(s) to the effect you are trying to achieve. Such functions can be found in the files titled "...Logic.swift"

Of course an effect often contributes a cause to some other effect. You will see such code with the network request and when a user chooses an item from the table view of one view controller which influnces the output of a different view controller.

The system also allows us to bundle a bunch of cause-logic-effect chains into a single effect. Examples include the functions that create view controllers. These are cause/effect bundles.

The benefits of the architecture is that logic is isolated and easy to test without the need for test doubles. No mocks, fakes or stubs. No need for dependency injection. New features can easily be added by simply outlining the effects of the new feature, or changes to current effects. Bugs are easy to isolate because all the causes for a particular effect, as well as the logic for that effect, are fully self-contained in a single function.

Declarative Style

Most example programs are written in an imperative style, where any particular line of code represents a step in a process and doesn't tell you anything about the process as a whole. Writing with reactive extensions gives me the chance to write code in a more declarative style where each function doesn't just represent a step in a process, but rather it represents a fundimental truth, something that will always be the case. I wrote a short article about this subject. Imperative vs Declarative Programming


If you have any questions about how the code is written, or about the code itself, I would love to read them. Post an issue with your question and I'll do my best to respond. I am also active in the RxSwift slack channel as well as on Stack Overflow.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].