Are you interested in different architectural patterns? Are you stuck on Apple’s MVC pattern and could not find time to learn new architectures? Or you want to write more clean, structured, testable code?
If your answer is YES for all of the questions above, you might be interested in this post.
First thing that I should say: this is not a tutorial. It is just a simple post for motivating myself and being helpful to anybody who are saying yes for the questions that I wrote above.
Why should we choose an architecture?
There are lots of different types of architectures that we can prefer to use such as MVC, MVP, VIPER or MVVM while developing iOS apps(and/or other platforms). There are main purposes for choosing an architecture before starting to develop an iOS project. Developing a project with an architecture:
- Forces you to write well separated, more readable code,
- Easier to apply SOLID principles as close as possible,
- Helps you to write unit tests easier,
- Helps you to reduce code size of view controllers’ to prevent them to become a Massive View Controller’s.
There is no specific reason for me choosing MVVM to learn. But here is a list that why I am choosing it rather than the others:
- Popular to use.
- Easy to find good sources for learning.
- I hear that it is commonly used by lots of popular companies for their featured apps on App Store.
- Some people say Reactive Programming is future (it has a good relationship with MVVM).
- I saw that lots of companies are looking for candidates who have MVVM or/and RxSwift/RxCocoa knowledge. Looking at job posts is a good way for following and learning trends for improving your skills.
Learning new architecture is exciting but it’s challenging. Once you are starting to learn MVVM, you will see the “data binding” thing. And you have to choose one of the “data binding” options.
Let’s see what I have done.
Which option to choose for data binding?
Here is an awesome tutorial for learning MVVM from scratch. In this tutorial, the instructor is telling that there are few options to bind the data. The video is about an hour but I am going to summarize it for you:
- Functional Reactive Programming (FRP)
- Property Observers
MVVM is famous for synchronizing data between UI and the model using viewModel’s and you have to bind your data by using one of the options that I listed above.
Best way to learn something new is practicing. So, I decided to make a simple app that fetches data from iTunes API and lists tracks.
Actually, the first part of the demo is over for me. I have made some research about MVVM and looked at a few example projects on GitHub after watching the video that I shared above. I chose the “Boxing” option for data binding as instructor did. Using “Boxing” is a pretty easy option while understanding the basics of MVVM.
Here is the source code:
An example app for practicing MVVM architecture with using iTunes API. - gultekingokhan/iTunesInMVVM
The first part for me was learning basics of MVVM and it went well for me. I am planning to add some features for improving my knowledge about it:
- Search & list results
- Detail screen for showing more data about the track
- Or just make a basic music player to listen to the preview of the track
If you are interested, you can watch the repository for getting notified about the updates. If this post motivated you to learn or found it useful you could give a 👏 or buy me a coffee😄 💪
Thanks for reading!
Note: If you see anything wrong in this post, please comment so I can update it as soon as possible. Also I will be glad if you make pull requests 🙏