IOS block loop reference solution, iosblock loop reference
Before introducing block loop reference, let's take a look at typeof.
What is typeof ???
Typeof is a one-dimensional operation. Before a single operation, the operation can be of any type. The return value is a string that represents the type of the number of operations.
1. For numeric operands, the value returned by typeof is number. For example, for typeof (1), the returned value is number. The preceding figure shows the regular number. For an unconventional number type, the result returned is also number. For example, typeof (NaN), NaN represents a special non-numeric value in JavaScript, although it is a numerical type.
2. For the string type, the value returned by typeof is string. For example, the value returned by typeof ("123") is string.
3. For boolean type, the value returned by typeof is boolean. For example, the value returned by typeof (true) is boolean.
4. For objects, arrays, and null, the returned values are objects. For example, the values returned by typeof (window), typeof (document), and typeof (null) are all objects.
5. For function types, the returned value is function. For example, typeof (eval) and typeof (Date) return all function values.
6. If the number of operations is not defined (for example, a non-existent variable, function, or undefined), undefined is returned. For example, typeof (sss) and typeof (undefined) both return undefined.
After learning about typeoy, you can understand the weak reference of block.
Why use weak references ???
We know that the block length matches strong, but we also need to respect the issues left over by MRC. Therefore, we often find that copy, the two methods have the same effect in ARC. Since we can see strong, copy must take into account the issue of strong references.
We can understand the concept
The object has a Block attribute. However, if other member variables of the object are referenced in this Block attribute, the variable itself will be strongly referenced, then the variable itself and its own Block attribute form a circular reference. Therefore, we need to process it for weak reference.
How to Implement weak references ???
The following is a simple code:
- _ Weak typeof (self) weakSelf = self;
- Self. Block = ^ {
- If (weakSelf. people ){
- WeakSelf. people. name = @ "xubao loves fish ";
- }
- }; This is just a brief introduction. You still need to exercise more to master it.