首页 > 代码库 > objective -c こだわり
objective -c こだわり
You make an object by creating an instance of a particular class. You do this by allocating the object and initializing it with acceptable default values. When you allocate an object, you set aside enough memory for the object and set all instance variables to zero. Initialization sets an object’s initial state—that is, its instance variables and properties—to reasonable values and then returns the object. The purpose of initialization is to return a usable object. You need to both allocate and initialize an object to be able to use it.
A protocol defines a set of behaviors that are expected of an object in a given situation. A protocol comes in the form of a programmatic interface, one that any class may implement. Using protocols, two classes distantly related by inheritance can communicate with each other to accomplish a certain goal, such as parsing XML code or copying an object.
Any class that can provide useful behavior to other classes can declare a programmatic interface for vending that behavior anonymously. Any other class can choose to adopt the protocol and implement one or more of the protocol’s methods, making use of the behavior.
MVC
Model-View-Controller (MVC) is central to a good design for any iOS app. MVC assigns the objects in an app to one of three roles: model, view, or controller. In this pattern, models keep track of your app’s data, views display your user interface and make up the content of an app, and controllers manage your views. By responding to user actions and populating views with content from the data model, controllers serve as a gateway for communication between the model and views.
As you’ve built your ToDoList app, you’ve followed an MVC-centric design. The interface you built in storyboards makes up the view layer. AddToDoItemViewController and ToDoListTableViewController are the controllers that manage your views. In Tutorial: Add Data, you’ll be incorporating a data model to work with the views and controllers in your app. When you begin designing your own app, it’s important to keep MVC at the center of your design.
objective -c こだわり