Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Weather App with Swift Managing Complexity Network Operations

Iman Mk
Iman Mk
6,223 Points

MVC Design

Regarding MVC design, if all I'm doing is getting data from database or updating data in the database then would my requests be in viewControllers? Or do I have to have another class as a model for users that holds some user data from database? I understand that in this situation the database would be the Model and View and Controller are within the iOS app. So it will form the MVC as a whole. But I am not sure if I should have another class just for network operations or is it fine to do that within the controllers whenever needed?

1 Answer

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

You could do it that way, but I don't think if you even have a small amount of code that it is a good idea. 1) It's messy. If you model it correctly the code is much cleaner and easier to navigate. 2) It doesn't follow development protocol. My guess is a company will more likely hire somebody who follows convention. And 3) You need to form the habit. If you don't form the habit now, you might forget or not know how to do it in bigger projects.

Hope this answers the question!

Iman Mk
Iman Mk
6,223 Points

Hi Caleb,

Thanks for your response. I completely understand the importance of following conventions and software design patterns. As you know in MVC, controller gets the data from model and updates whatever it's needed in view. Or gets the data from view and updates the data model. Let's say we have a SQL database that the web developer wrote and he also wrote a little API for for queries in JSON. My understanding is that for instance in sign up page I get user's info from view via controller. Then, I have to update the database with the functions that the web developer gave me using Alamofire and SwiftyJSON. So there won't be a lot of local storing in the app and I'll be just using some interfaces. In that regard, should I make the http requests in e.g. signupViewController? Otherwise, specifically how should I approach that?

Thanks in advance!