Differences between strong and weak in Objective-C

后端 未结 9 1259
礼貌的吻别
礼貌的吻别 2020-11-22 08:09

I\'m new to Obj-C, so my first question is:

What are the differences between strong and weak in @property declarations of poin

9条回答
  •  情话喂你
    2020-11-22 08:24

    strong and weak, these keywords revolves around Object Ownership in Objective-C

    What is object ownership ?

    Pointer variables imply ownership of the objects that they point to.

    • When a method (or function) has a local variable that points to an object, that variable is said to own the object being pointed to.
    • When an object has an instance variable that points to another object, the object with the pointer is said to own the object being pointed to.

    Anytime a pointer variable points to an object, that object has an owner and will stay alive. This is known as a strong reference.

    A variable can optionally not take ownership of an object that it points to. A variable that does not take ownership of an object is known as a weak reference.

    Have a look for a detailed explanation here Demystifying @property and attributes

提交回复
热议问题