Home » IOS » The operation mechanism of IOS in three common mec...

The operation mechanism of IOS in three common mechanism

/**

* a member variable cannot be defined in a category and cannot define property
directly
* if you define an attribute, you must override the getter&setter method
yourself
*



If the classification can achieve record attributes, function.

Need to use the 'runtime mechanism', is to develop OC language,
!


Three scenes are used in everyday development,

1. in classification, by adding attributes to the classification dynamics by association objects, the classification can be decoupled, and the frame.
can be developed
2., dynamic access to a list of attributes of the class, you can develop dictionary model transformation model framework.

3. exchange method, the address of dynamic exchange method, mainly used in take over system method,.

*

*

*/

/**

* dynamic association properties

1. the object
associated with
The key const void *key of the 2. attribute defines a constant (syntax equivalent to ID)

3. the value of the record attribute

4. references to associations

Assign
in OBJC_ASSOCIATION_ASSIGN ARC
COPY
in OBJC_ASSOCIATION_COPY ARC
Thread protection issues in OBJC_ASSOCIATION_COPY_NONATOMIC
ARC
OBJC_ASSOCIATION_RETAIN

Strong
in OBJC_ASSOCIATION_RETAIN_NONATOMIC ARC


The difference between weak and
is assgin
The same point:

Neither strongly references.

Difference:

The object referenced by weak, which automatically points to nil
once the reference count is 0
The object referenced by assign, once the reference count is 0, the object address is unchanged, so the wild pointer problem occurs under MRC. It is also a common bug



Objc_setAssociatedObject (<#id, object#>, <#const, void, *key#>, <#id, value#>, <#objc_AssociationPolicy, policy#>)

copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest