IOS block loop reference solution, iosblock loop reference

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.