An example iOS MVVM app with RxSwift with Realm.
Use MVVM
with RxSwift on the app (except on the simplistic PostViewConroller
screen to avoid overengineering.)
Post
represents posts in the timeline implemented as aRealm
object.
These view models use RxSwift
to update their associated views. The pattern is:
- Their variables are
Observable
s. The view'sUIControl
s can bind to them to update the screen. - Their callback are
Observable
s. The view can bind to them to receive the view model method's responses.
The reactive views own their associated view models. (See createCallback
) The view can call a view model's method
and receive the method's response by binding the view model's events.
The views also are subscribe to the changes of the view model's changes on the models
in order to correctly update the screens. (See bindViewtoViewModel
)
It implements UITableViewCell
used by TimelineViewController
. It uses customed
NSLayoutConstraint
to programmatically adjust the layout to display different number of photos.
This app uses Realm
for database. It stores 1 model class, Post
.
Note that Post
database doesn't directly store image binary into the Realm
database. When
a Post
object is saved, it first copies images to the user's documents
directory, then only saves
the file names in the Post
object. This will scale better the read/write time performance when
the database grows with more and larger images.
When the app first launches, it does so with pre-populated data for the ease of demo. See
SeedData
class.
The XCTest
is used to test model's logic and operations.
TestUtils
tests the foundation logic and outputs.TestViewmodels
tests the view models themselves and the model CRUD. When running these unit tests, we switch to use in-memory Realm database config so that it does not mess up the app's current database.
The XCUITest
is used to test the UI interactions implying correctness of
the app's navigation and view mode's reactive wiring. Each time UI test is runned,
the database resets to its test data state. The test automation recorded is
strictly dependent on the test data created by the SeedData
class.
MyTimelineUITests
tests each part of the navigation of the main 3 screens, search and full image viewer.