[Swift / Beginner] Let's write the functions around communication in a separate file

When I'm new to studying, I think I've written all the processing in the view controller.

The view controller created in such a way is ** FatViewController **,

It is called a fat view controller.

The higher the FatViewController, the less readable and maintainable it becomes.

To prevent this, there is a design concept called ** architecture **.

View related processing here, business logic here, etc.

This is a rule that does not reduce the code quality.

It's difficult to follow this from the beginning, so let's first isolate the API communication.

Separate processing around communication

First of all, the processing around communication -Function that throws API (returns response with closure) Throw a request and return the response in closure. -Structure (Codable) for mapping the response The part that conforms to Codable and codes according to the returned Json data -Process API response Processing that actually uses data I will divide it into three parts.

If you can do this first You can take one step on the road to becoming a beginner.

in conclusion

Finally, if you can code according to the architecture called MVVM I'm completely new to the game, but it's difficult from the beginning At the very least, please be aware that you should write separately even around communication.

Recommended Posts

[Swift / Beginner] Let's write the functions around communication in a separate file
[Swift, a must-see for fledgling! ] Let's understand the implementation of communication processing of WebAPI
Let's write a Qiita article in org-mode of Emacs !!
Let's make a calculator application in Java ~ Display the application window
What if I write a finally clause in the try-with-resources syntax?
Get the public URL of a private Flickr file in Java
Add a time stamp to the JAR file name in Gradle
Let's write a test code for login function in Spring Boot
Let's create a TODO application in Java 5 Switch the display of TODO