-3

I am (trying to) learn Objective-C and I keep coming across a phrase like:

__weak IBOutlet NSLayoutConstraint *webViewLeftConstraint;

What does __weak it mean exactly in Objective-C? Why we need to put __(underscore twice) in variable? Can we use only one time? like( _ ) other declaration in other language..

Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
NemSothea
  • 169
  • 1
  • 2
  • 10

1 Answers1

1

If the outlet is referencing a UI Object in the View hierarchy then you should make it weak as the view hierarchy already has a strong reference.

Weak is specifically needed to avoid a retain cycle.

Arpit Jain
  • 1,660
  • 12
  • 23