Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the strong property attribute

I am using the Xcode beta for developers, and am noticing some subtle differences. Among them is a new attribute for declared properties.

@property(strong)IBOutlet NSArrayController *arrayControl; 

My question is: what does the strong attribute mean?? Does it replace some older one, or is it something entirely new? I have searched through google and the developer documentation and havent been able to find anything. Until i know what it is i am hesitant to use it.

Thanks in advance

like image 935
Chance Hudson Avatar asked Jul 14 '11 23:07

Chance Hudson


People also ask

What is a weak property?

1. When we declare weak property then it only contains data/instance address till strong reference is in memory if strong variable reference deallocated it is automatically set to nil. For ex:- var str = "hello world" weak var stringVar = str.

What is Nonatomic property?

Nonatomic means multiple thread access the variable (dynamic type). Nonatomic is thread unsafe. But it is fast in performance. Nonatomic is NOT default behavior; we need to add nonatomic keyword in property attribute.

What is assign in iOS?

assign(to:on:)Assigns each element from a publisher to a property on an object. iOS 13.0+ iPadOS 13.0+ macOS 10.15+ Mac Catalyst 13.0+ tvOS 13.0+ watchOS 6.0+


2 Answers

It's a replacement for the retain attribute, as part of Objective-C Automated Reference Counting (ARC). In non-ARC code it's just a synonym for retain.

like image 91
Lily Ballard Avatar answered Sep 21 '22 15:09

Lily Ballard


A strong reference is a reference to an object that stops it from being deallocated. In other words it creates a owner relationship. Whereas previously you would do this:

**// Non-ARC Compliant Declaration @property(retain) NSObject *obj;** 

Under ARC we do the following to ensure a class instance takes an ownership interest a referenced object (i.e. so it cannot be deallocated until the owner is).

**// ARC Compliant Declaration @property(strong) NSObject *obj;** 
like image 29
Jack Farnandish Avatar answered Sep 20 '22 15:09

Jack Farnandish