- Get link
- X
- Other Apps
MVC:
- View is supposed to be inactive and only displays prepared data on demand.
- Model: It represents simple data.
- Controller should work on the Model data to prepare it for the Views, which then display that data.
- View is also responsible for notifying the Controller about any actions, such as user touches.
UIViewControlleris supposed to be a Controller in the MVC pattern,
MVVM:
The Model View ViewModel (MVVM) is an architectural pattern used in software engineering.
- Models hold application data / Content. They’re usually structs or simple classes.
- Views display visual elements and controls on the screen. They’re typically
UIView and UIViewController. xib and storyboards - View models transform model information into values that can be displayed on a view. They’re usually classes, so they can be passed around as references.
- ViewModel hides all asynchronous networking code, data preparation code for visual presentation, and code listening for Model changes. All of these are hidden behind a well-defined API modeled to fit this particular View.
- Test covering in ViewModel is rather easy as it does not contain any reference to a view. Rather it only prepares data for the view only. It is the view that pulls the data from the view model. Also, the view delegates the action to the View model.Since ViewModel is pure
NSObject(orstructfor example), and it’s not coupled with theUIKitcode, you can test it more easily in your unit tests without it affecting the UI code. - Application is easer to maintain and extend.
- Application is easier to unit test.
the View (UIViewController/UIView) has become much simpler while ViewModel acts as the glue between the Model and View.
Popular Posts
escaping closure and closure
Closures are self-contained blocks of functionality that can be passed around and used in your code. let greeting:(String) -> () = { name in print("Hi, \(name)!") } birthday("Bebo") An escaping closure is a closure that’s called after the function it was passed to returns. In other words, it outlives the function it was passed to. A non-escaping closure is a closure that’s called within the function it was passed into, i.e. before it returns.
Certificate pinning and Alamofire
1. Alamofire and URLSession. both help you to make network requests in Swift. Main advantage for Alamofire: Certificate pinning . It can take some time to sort this out and build this yourself. Asymmetric cryptography : The second phase uses public-key cryptography or asymmetric cryptography . This is a cryptographic system that uses pairs of keys: Public keys, which are widely disseminated and private keys, which only the owner knows. The third phase uses symmetric-key cryptography , where you use the same key for both encryption of plaintext and decryption of ciphertext. In other words, you configure the app to reject all but one or a few predefined certificates or public keys. Whenever the app connects to a server, it compares the server certificate with the pinned certificate(s) or public key(s). If and only if they match, the app trusts the server and establishes the connection. You usually add a service’s certificate or public key a...
Comments
Post a Comment