Strong pointers: By default, all pointers are
is a strong pointer type (strong) in Arc
, an object that has no strong pointer reference
Then it will be recovered by the system.
Weak pointers: Weak pointers do not affect the collection of objects
In Arc, all the manual memory management
None of the related methods can call for example
Dealloc cannot override the parent class (cannot
Super Dealloc)
__weak defines a weak pointer
__weak person * p2 = p//weak pointer
Does not affect the object
A strong pointer reference uses the OC object type,
@property (Nonatomic,strong)
We use other people's projects, it's possible to use right and wrong
ARC's Project
-fno-objc-arc
-f-objc-arc
Third-party framework: is the project written by others,
We're going to use if he's a non-arc mechanism that gives
The compiler adds a parameter-fno-objc-arc
is to tell the compiler that this file is a non-arc machine.
So that no error is made, and the non-
Arc Manual memory Management method can be normal
Called to introduce an arc machine in a non-ARC project
File, add a parameter to the compiler-
F-bojc-arc, is to tell the compiler this article
is the arc mechanism.
Edit->refactor-convert to
ARC Circular Reference problem
If a circular reference problem occurs in the ARC mechanism
, you just have to turn it into a reference,
Weak weak pointers can solve problems
Block type
int bool Char float double
NSObject * ID SEL
Their common feature is the ability to define changes
Amount
1.int a = 0;
BOOL B = YES;
2. As a function, and the method of passing parameters
(void) test (int) A
Block: Is a more specific type of data in OC
That is used to encapsulate a piece of code and can
Pass this code as a parameter
1. Encapsulating code with {}
1.void Test (): The return value is empty, and no
Have parameter {}
^{};
2.int test (), with a return value, and a parameter
Number
^{return 10;}
3.int Test (int a); there is a return value, and a
A parameter
^ (int a) {return a + 1}
4.int Test (int a,int b) has a return value, with
Multiple parameters
1. Define a return value of NULL, and No
The block variable of the parameter
void (^myblock) () = ^{};
2. Define a return value, and there is no
The block variable of the parameter
Int (^myblock) () = ^{return
10;};
3. Define a return value, and there is a
The block variable of the parameter
Int (^myblock) (int a) = ^ (int
A) {return a + 1};
4. Define a return value, and there are multiple
The block variable of the parameter
Int (^myblock) (int a,int b) =
^ (int a,int b) {return a + B}
The advantage of block is that I define block
itself can not care
Implementation of block internal algorithm
Who calls the method that has the block parameter, who is
Give me the block internal algorithm.
Agreement
Protocols are used to declare methods.
@protocol MyProtocol
-(void) test;
@end
Methods in implementing the Protocol in. m
@required indicates that the following methods must implement
-(void) test1;
@optional represents an optional implementation
-(void) test2;
Optional, it's not in the class that complies with the protocol.
Inside display
However, required will prompt you to
Is
The protocol itself, he can follow other protocols.
Protocols can follow multiple
Base protocol
Protocols are used to declare methods.
@protocol MyProtocol
<NSObject>
Internal Declaration method
@end
Constraints of methods within an agreement
@required the methods that must be implemented
@optional Select the implementation
The default method is the one that must be implemented
Having a class follow the protocol requires only the class to inherit
Back < Agreement name >
Class can follow multiple protocols < protocol names, and the protocol
Name, protocol name >
The agreement itself may also be subject to other agreements < agreements
Name >
Member variables cannot be declared in the protocol
The subclass inherits the parent class and also inherits the parent
The protocols that the class follows
NSObject * obj = [[NSObject]
INIT];
ID obj2= [[nsobject alloc] init];
When you define an OC object variable, you can add
A protocol constraint
Person<myprotocol> *p =
[[Person alloc] init];
@property (Nonatomic,strong)
car<myprotocol2> * CAR;
If you want to qualify an object, be sure to
Agreement, then we generally use
Id<myprotocol2>obj to define
@property (Nonatomic,strong) ID
<Myprotocol2> obj;
Just like the @class function, it tells the class
, MyProtocol is an agreement
@protocol MyProtocol;
Declare the protocol to a. h file of a class,
Other classes of inheritance, there is no way to follow this
An agreement.
Define the protocol individually as a. h, any class
Can follow this agreement,
This article is from the "Ten Years" blog, please be sure to keep this source http://yanshinian.blog.51cto.com/8275527/1564567
iOS Black Horse programmer--arc