Stanford iOS7 Open Class 1-3 notes and Solitaire Demo

Source: Internet
Author: User

1.MVC

Model: Models

Describe what the program is, such as database manipulation, and the card play is written on the model layer, through notification and KVO (subsequent articles will be introduced) two ways to communicate with the controller.

Controller: Control Layer

The logic of the program is organized here, and the Controller is responsible for the communication between model and view, because model and view Laosi.

When the user is working on the page, the controller collects the user's interaction information, then asks how the model responds, the model receives the question from the controller, and then gives the answer (the controller does not ask a question, the model will never answer voluntarily). After the controller collects the response from the model, it updates the UI page as appropriate.

When the UI control is connected to the controller, the controller's outlet interface appears, through which the controller can communicate directly to the UI control.

View:ui page

After the program runs, the user will see this layer, the user's interaction information can be delegate, DataSource and Target-action three ways to communicate with the controller.

In the case of a card demo, the right side is the page after the program runs, the View layer,

The list on the left is a series of files in the model layer, defining a series of gameplay and how to play the card game.

Cardgameviewcontroller is the controller layer, collect the page click Information, find the model method, and then to update the page effect.

The benefit of MVC is that code separation not only makes the code structure clearer, but also facilitates subsequent iteration updates, especially the code in the controller, to avoid entanglement with the UI element settings at the controller level.

, the model layer is created in the card demo to make the code more concise and clear (commented out as part of the code used before separating the model).

2.h files and. m files

Objective-c. h files are primarily used to declare public interfaces, including declaring classes and their methods. The. m file is responsible for the implementation, or you can define a private interface that you do not want to expose.

The introduction of the header file will see two kinds of writing, referring to the system comes with the general use of #import <xx.h>, referring to custom general #import "XX.h", The difference is "" means to start looking for files from the current project path, if not found, then to the project configuration of the header file path to find. <> represents the header file path directly to the project configuration to find.

[email protected], nonatomic, strong

In the code you will see these keywords, after using @property declaration variables, Xcode4.5 and later versions of the compiler will automatically generate setter and getter method, if not special needs, you can directly use the underscore variable name ("_name") for the assignment value operation.

Atomic is a protection mechanism to prevent the simultaneous reading of data in multi-threaded operations, which consumes some resources, typically using nonatomic in a single thread.

Strong, weak represent strong and weak references (used in ARC environments, XCODE5 later default to ARC environment), when using the strong declaration variable is a strongly referenced type, it means that as long as there is a pointer to the variable, it will always exist in memory. It is destroyed unless all pointers to it point elsewhere or become nil or explicitly assign a value of nil to the variable.

using weak is different, such as Viewcontroller can be found in the UI control is generally weak type, the compiler will automatically trace to who owns the weak reference variable, when the owner destroys, The variable is automatically assigned nil, that is, the UI control to which it belongs is nil after the view is destroyed.

4.ios7 new Features Instancetype

It is recommended in the course that the Init method use Instancetype instead of the ID, and when the return value is consistent with the message receiver type, it can be used instancetype, allowing the compiler to do some checking work automatically, and we can automatically check that the return value type is valid when we write the code compile phase. But instancetype can not be used as an ID as a parameter, temporarily not in-depth study, interested can refer

http://blog.eddie.com.tw/2013/12/16/id-and-instancetype/

5. The final effect of the card demo used in the course, the source is attached:http://files.cnblogs.com/colinhou/Matchismo.zip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.