IOS Block Circular Reference

Source: Internet
Author: User

Before we introduce the Block circular reference, let's take a look at typeof.

What is typeof???

TypeOf is a unary operation that can be any type before it is placed in an operand. The return value is a string that describes the type of the operand.

一、对于数字类型的操作数而言,typeof返回的值是number。比如说:typeof(1),返回的值就是number。 上面是举的常规数字,对于非常规的数字类型而言,其结果返回的也是number。比如typeof(NaN),NaN在 JavaScript中代表的是特殊非数字值,虽然它本身是一个数字类型。

二、对于字符串类型,typeof返回的值是string。比如typeof("123")返回的值是string。

三、对于布尔类型,typeof返回的值是boolean.比如typeof(true)返回的值是boolean。

四、对于对象、数组、null 返回的值是 object 。比如typeof(window),typeof(document),typeof(null)返回的值都是object。

五、对于函数类型,返回的值是 function。比如:typeof(eval),typeof(Date)返回的值都是function。

六、如果运算数是没有定义的(比如说不存在的变量、函数或者undefined),将返回undefined。比如:typeof(sss)、typeof(undefined)都返回undefined。

Understanding Typeoy to understand the weak references of blocks

Why use weak references???

We know that the block length is a match with strong, but we also need respect for the MRC legacy, so we will find copy in many cases, and the two effects are the same in arc. Now that you see strong,copy, you have to consider the issue of strong references.

We can understand this.

Object has a block property, but the block attribute also references the other member variables of the object, then the variable itself is strongly referenced, then the variable itself and his own block property form a circular reference. So we need to do a weak reference to handle it.

How to implement weak references???

Here's the simple code:

    • __weak typeof (self) weakself = self;
    • Self. Block = ^ {
    • if (weakself.people) {
    • WeakSelf.people.name = @ "..... ";
    • }
    • }; Here is a simple introduction, want to master or need more practice.

This article reprinted from @ "Xu Bao Love to eat fish"

IOS Block Circular Reference

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.