Lesson Two:
1. Lazy Initialization
1 -(ObjectType *) example2{3 F (!_example) example =[[ ObjectType alloc] init]; 4 5 return _example; 6 }
Initialize the variable until the last moment before use
2. Array literal format
@[a,b,c,..., M,n];
3. @synthesize
An explicit composition is required when overriding the property's setter and getter method, otherwise the compiler generates @synthesize example = _example by default;
4. Class methods
1 + (ReturnType *) example2{3 /// cannot use class properties in class methods 4 // used as a factory method 5 // typically used to create an instance object 6 }
5. Method of Object initialization
Framework:
1 -(instancetype) init2{3Self = [Super init]4 if(self)5 {6 // Custom initialization content 7 }8 return self ; 9 }
Specify the initialization method:
Typically, the default is the public API, which specifies the initialization method to use, and the rest of the initialization methods must call the specified initialization method to complete the initialization. No syntax formatting, usually illustrated by annotations. Similarly, a method is specified for a class of methods.
6. Xcode Basic Use
See Video or Courseware PDF
7. Outlet and action
A link between the UI and the controller, implemented through Ctrl+drag.
Ibaction is actually void for xcode recognition, and the compiler automatically ignores it.
The Iboutlet is actually tagged for xcode recognition, which the compiler automatically ignores.
1 #define ibaction void 2 #define iboutlet
8, NSLog ()
C language function, used in the console printout, can be used to test the program run time,
(The author notes: We do not directly use the NSLog () function when we actually write the app, because the app does not nslog () output when it is compiled, so we need to pre-compile the debug version with NSLog () and cancel NSLog () in the release version. You can insert the following code in the PCH file or in the appropriate place
1 #if DEBUG2#define yourprefixlog (...) NSLog (__va_args__)3#else4#define yourprefixlog (...) 5 #endif
You can then replace the previous nslog () with Yourprefixlog () directly in the program where the printout is required. )
9. Homework
A. Creating a Matchismo project with Xcode
B. Create and enter the previous 4 objective-c classes: Card,playingcard,deck,playingcarddeck
C. Add a private property of the deck class for Viewcontroller
D. Initialize the deck to a stack containing playingcard using lazy initialization of the above properties
E. Realization of a card on each click of the heap randomly in the stack of cards
F. Cannot destroy the original function structure
See Https://github.com/NSLogMeng/Stanford_iOS7_Study_Machismo (This homework answer for the course to announce the correct answer, follow-up course homework no standard answer, the author only with personal understanding answer, welcome correct)
Course Video Address: NetEase Open class: Http://open.163.com/movie/2014/1/H/R/M9H7S9F1H_M9H7V38HR.html
or itunes U search Standford Course
(2/18) Re-learning STANDFORD_IOS7 development _xcode_ Course notes