
Introduction
Before you begin to learn the basic syntax of Cocoa (the API created by Apple for writing desktop Mac applications in Objective-C), you must first gain a firm grasp of the following two concepts:
a. Object Oriented Programming
b. The Model-View-Controller System (MVC)
Object Oriented programming is a way of writing code that allows you to create multiple “objects,” which each have properties, and actions that they can perform. The MVC System provides a basic guideline for organizing a project with multiple classes that each perform specialized tasks.
Object Oriented Programming
I’m going to go out on a limb here and use a car analogy. Ever model of car has its own blueprint, which the manufacturer uses to build lots of copies of this same type of car. Yet once each car has been created, it is given its own defining features, such as color, drive, and location. The owner can customize their car by doing lots of unique actions to it (painting it a new color, replacing the seats, etc.) But no matter how much the owner customizes their car, it is still based off of the original blueprint that was created by the manufacturer.
Jump time. The blueprints that the manufacturer used to make lots of copies of this same model of car are now called classes. Each car is now an object, and each object is an instance of the class. All of the little defining features of each car, those are variables. And the little actions that the owner takes to customize the car, those are methods.
Take a deep breath, that’s a lot to take in in such a short amount of time. Lets go over it again, shall we?
Class: A blueprint. A definition of how an object can be created.
Object: An instance of a class. In other words, something built from a certain blueprint.
Instance: An object that was created using a class as a blueprint. For instance, for the car analogy, a Porsche 911 owned by myself (I wish) would be an instance of the Porsche 911 class.
Variable: A property of an object. Something that defines it. In the car analogy, the color of the car would be a variable.
  Method: An action that something can take that changes a variable of an object. Using the car analogy, this is something that a person can do to change the properties of the car.
So, I know what you’re thinking: How the hell does this relate to Programming? Well, I’ll give you a real-world example:
Say I want to have an app that, when it starts up, display a window. Quick Disclaimer: This code is BY NO MEANS something that would actually work, so do NOT write to me, telling me that my example doesn’t work. This is just to drive my point home. To do so, I would send a message to the application telling it to display a window. In this case, the application that I’m sending a message to is the object, and the message I’m sending is what we call the method. Remember, a method is an action you can take on an object. Again, this wouldn’t actually work, but…
[Application displayWindow];
Make sense? Good. I’ll go over more of proper Objective-C syntax in a later tutorial, don’t worry.
I dunno about you, but I am totally ready to move on to MVC!
The Model-View-Controller System
Now you’re thinking: Crap, this sounds complicated…and it is! Nah, not really. You just have to understand what we’re going for. The idea of MVC is it is simply a way of organizing the way that the User Interface (UI) interacts with the code, and how the code in turn can change things in the UI and respond to the user. To explain, I’m just going to give you a description of each element of MVC (keep in mind, these do not go in the order that they communicate in):
Model: The model is the code base of the application. For example, a calculator’s model would be the class that handles operations such as multiplication, division, and more complex things if it was needed. Keep in mind, the model should never interact with the interface or the user directly. This kills the whole system. It can, however, send messages to the controller about what the results of an operation are, and the controller can send orders to it.
View: This is the interface that the user interacts with or sees. In our calculator example, this would be the actual window with buttons and a numerical display area. The view can send messages to the controller about what the user is doing, but it cannot talk directly to the model. Again, this kills the whole system.
Controller: This is a relay station of sorts. The controller takes actions sent by the view (from the user), and tells the model what to do. The model then sends back whatever data should be displayed to the user, and from there, the controller can tell the view to display it.
I know this all may seem fairly complicated, but if you look at any well-known open-source Cocoa project, you’ll see that this is the accepted way of organizing your code. You’ll do fine with it as long as you remember that the key is to separate the brains of the application from the interface that the user sees.
Related posts:
- Programming a Menu Bar Button The goal of this tutorial is to teach you...
- Basic C Programming In This tutorial, we will look at the basic principles...
- Word Counter using Bindings Bindings in Cocoa are very powerful and can be...










2 Responses
Today, many media and Alloy decorated with the vivienne westwood earrings vivienne westwood earrings r artist the best recycled plan to decorate cheap Vivienne Westwood jewelry devices and adapt them to new, the alpha and the avant-garde art. It is clear that to live in the best ornament to improve all the ornaments off. It is, however, vivienne westwood earrings n the majority comes from the different awards, which is admirable, but the lack of acceptance of their place of residence, this avant-garde world. In fact I predict that it is really unfortunate. There is an additional advantage as the destruction of the old abandoned plans to art has changed, and the corresponding width of the new jewelry. Altered properties of the best ornament design, it is a custom piece of congenital, adapted accommodation to access the full angrily tempting. In fact, all my suggestions blot some vintage ornaments. I am still interested to take effect until the blot is always the best tool for the design vivienne westwood jewellery vivienne westwood jewellery j and width I. It assures me that the purchase is made of art a new home instead of being recruited to the trash. However, I agree that he is in fact difficult to buy the best pieces adorn the top goals I’m going to stud. Fit to be admired my work plan for the top spots above the age of the best and pearls. Truth be told, well-shaped architectural ornament, which contains the update history of Birr is acceptable for the soul. Posted importantly, added a turn off than the width of the acerbic history. In some exceptional way, which is connected to and maintain a complete history of alpha in our hearts. You can find really ridiculous to the best equipment to travel through the sale barn, aged Vivienne Westwood’s Jelly Shoes Vivienne Westwood was brooches shots, flea markets, or even limited to bean store, but the approval of bigg vivienne westwood jewellery r Vivienne Westwood glasses frame R luck, when the device on the Internet. The best approach is to analyze the best search terms. In searching for “vintage elements” can be full of amazing plants and results in a sudden, the search is added to the aesthetic as “vintage beads and old,” can accurately analyze the items can be found. If you are a borderline case terminology, alpha enough to search, such as “antique ornaments components.” It may take you a host of advice and the agreement again, you can control which areas of absorption would like to do some searching. Finally, bonds, and counter the key words and phrases into the Agreement to believe Vivienne Westwood dress for the acquisition essentially what your needs are. Finally, do not forget the hit bounded by saving deals. I agree to start decorating the unit at Best Best demographics in the afternoon every couple of weeks Vivienne Westwood Earrings Buzz Go to the shops. Vivienne Westwood cheap earrings usually cake Necklaces Vivienne Westwood’s acquisition of CES is available total. Unfortunately, it may not be as acceptable as the Vivienne Westwood wallets Arcade via the Internet, but much more abundant added rewarding agencies.
This article has given me an in-depth understanding of MVC unlike any other articles i’ve read so far! The analogies given in this article; car and calculator are perfect! You ROCK!