Platform iPhone-iPad
- Xcode 11+
- Swift 5
- iOS 15.0+
- First you need install Xcode from app strore on mac
- To run the project, clone the repo, and run
pod install
from the project directory first in Terminal application. - Then open the Media-Player.xcworkspace.
- if Cocoapod is not install on your system, do under task
sudo gem install cocoapods
I always found the architecture pattern is good to use, but we should not strictly follow an architecture pattern in our project. Not every architecture pattern is good enough to give you everything, there are cons & pros of every architecture pattern. if we have a lot of modules in our project, we can decide the architecture pattern according to the module also. Some module suits well with MVVM, but maybe your new module will not work well with MVVM, so instead use another architecture pattern like MVP, VIPER. So we should not completely rely on a single architecture pattern, instead, we can check it according to the module also.
There are lots of articles available over the internet explaining the definition and cons and pros of the MVVM pattern.
- Model: In the MVVM design pattern, Model is the same as in MVC pattern. It represents simple data. They’re usually structs or simple classes.
- View: View is represented by the
UIView
orUIViewController
objects, accompanied with their.xib
and.storyboard
files, which should only display prepared data. - View Model: View Model transform model information into values that can be displayed on a view. They’re usually classes, so they can be passed around as references.
Note that the class diagram at the top of this page includes a view controller; view controllers do exist in MVVM, but their role is minimized.
Our directory in project is:
- Commons: a collection of useful utility classes common to different iOS projects
- Modules: a collection of modules in application
- Resource: a collection of assets in application such as fonts, images, localize strings ...
Inside Each module we implement MVVM arch for example:
- D = Directory
- F = File
- O = Optional(it can implement inside other file, but sometimes doesn't need to create)
- Protocol D O
- Service Detail D
- Collection View Cells D O
- Table View Cells D O
- XViewModelContract.swift F O
- XViewModel.swift F
- XViewModel+Request.swift F O
- XViewController.swift F
- XViewController.Xib F
- XViewController+Binding.swift F O
- XViewController+TableView.swift F O
Protocols are a fundamental feature of Swift. They play a leading role in the structure of the Swift standard library and are a common method of abstraction. They provide a similar experience to interfaces that some other languages have.
In this directory we have request, response, service protocol, service.
Collect all collection view cells in this modules in this directory.
Collect all table view cells in this modules in this directory.
View Model transform model information into values that can be displayed on a view. They’re usually classes, so they can be passed around as references.
Seprate request of services in another file that cuased request is clear.
A view controller manages a single root view, which may itself contain any number of subviews. User interactions with that view hierarchy are handled by your view controller, which coordinates with other objects of your app as needed. Every app has at least one view controller whose content fills the main window.
Seprate bind request data from controller that cuased access function is simply
Handle table view data source and delegate in this file
Handle collection view data source and delegate in this file