. h header file, which declares some public properties, methods. Header files generally do not put too much stuff, there is no need to expose too many interfaces, private and encapsulation.
. m master file, used to implement methods in. h files, and some other methods.
-(return value) method Name parameter 1 Name: (parameter 1 type) parameter 1 function inside name parameter 2 name: (parameter 2 type) parameter 2 function name ...;
Call static (Class) method: [class name Method];
Invoke instance method: [variable name method];
A basic type of declaration that does not require a * modification;
#代表预编译处理符号
#include与 #import:
#include Introducing files
#import Prevent duplicate inclusions
Person.h
@interface Declaration section starts
Declarations section
End of @end Declaration section
Inheritance: Class Name: Parent class name
Category (extension): Parent class Name (class name)
Categories can extend the behavior of already existing classes.
Person.m
@implementation Implementation Partial Start
Implementation part
Partial end of @end implementation
Main.m
Alloc for allocating memory
Init performs initialization operations
The message passing mechanism is used in objective-c, and a class of operations such as calling methods, accessing properties, and so on, can also be called message passing.
@ Keyword (property modifier) type name;
Reference: http://blog.csdn.net/zhiganglet/article/details/7546333
Keywords:
Property: Automatic declaration of attribute read methods and setting methods such as
@property int personage;
The compiler automatically generates the following:
-(int) personage;
-(void) Setpersonage: (int) newvalue;
Synthesize: Implement property reading in main file the Relic setting method as
@synthesize personage;
The compiler automatically generates the following:
-(int) personage{
return personage;
}
-(void) Setpersonage: (int) newvalue{
personage = newvalue;
}
Property Modifiers:
ReadWrite (default)/readonly;
Assign/retain/copy;
Atomic (default)/nonatomic;
ReadWrite: Generating setter and Getter methods;
ReadOnly: Only generate simple getter, no setter;
Assign: By default, setter methods are directly assigned instead of retain;
Retain:setter method first release the old value, then retain the new value;
Copy:setter method for copy, as with retain;
Nonatomic: Prohibit multi-threading, protect variables, improve performance (
If multiple threads are used, there are times when two threads are waiting for each other to cause a lock to die.
In the absence of (nonatomic), the default (atomic) prevents such threads from being mutually exclusive, but consumes a certain amount of resources.
So if it's not a multi-threaded program, hit (nonatomic)
)
Property value Decoration after ownership
Strong |
__strong |
Yes |
Weak |
__weak |
No |
unsafe_unretained |
__unsafe_unretained |
No |
Copy |
__strong |
Yes |
Assign |
__unsafe_unretained |
No |
Retain |
__strong |
Yes |
Strong (default)
The property value corresponds to the __strong keyword, that is, the variable declared by the attribute becomes the holder of the object.
Weak
The attribute corresponds to the __weak keyword, which is consistent with the variable defined by the __weak, that the variable declared by the property will have no ownership of the object, and that the object will be automatically assigned nil after the object is discarded.
Also, delegate and Outlet should be declared with the weak attribute. Also, the weak property is not available if the previous version of IOS 5 that was introduced earlier has no __weak keyword. In this case we use unsafe_unretained.
unsafe_unretained
A variable equivalent to the __unsafe_unretaind keyword declaration, as described above, used by systems prior to IOS 5 in place of weak.
Copy
The difference from strong is that declaring a variable is the holder of the copied object.
Assign
The general scalar varible is declared with this attribute, for example, int, BOOL.
Retain
This property is consistent with strong; it's just more readable.
When the object holds a number of 0 o'clock, the system reclaims the memory occupied by the object.
OBJECTIVE-C study notes-First day (1)