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
jon kelson
5,149 PointsWriting a whole program in swift
Hi I'm just trying to get my head around the whole program writing concept. so..... When writing a whole program. do or can you write your functions with your statements etc in them and put them in a separate folder. Then ! Call them from what ? Another function or a main program . ? How does it all work in basic terms if you could please as I'm still a Beginner , Hope that makes sense . Thank you
1 Answer
Quinn Rodgers
9,561 PointsWhen you say "writing a whole program" do you mean like an iOS app? I'm going to assume that is what you are referring to in this case. iOS using a design pattern called Model-View-Controller or MVC and Swift is the programming language used to build the app.
Essentially the Model defines the objects and data within the application. For example, a model object might represent a character in a game or a contact in an address book. The View is the user interface of the application. For example, the view would contain the buttons, color, font choice, etc. And the Controller is the intermediary between the Model and View. For example, when a user clicks on a button the app saves the input to a database.
I prefer to keep my models, views, and controllers in separate files. When I need to call a specific function related to my model (for instance User) in my viewcontroller then I need to make sure there I have a user object instantiated within the viewcontroller and call the function on that object.
I've linked Apple's documentation on MVC if you care to read more. https://developer.apple.com/library/mac/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html
Hope this helps!