Differentiate between ‘assign’ and ‘retain’ keyword.



Differentiate between ‘assign’ and ‘retain’ keyword...

Answer / Prem Singh Jat

In Objective-C, both 'assign' and 'retain' are memory management keywords used with properties. However, they have different usage:
1. 'assign': It implies that the property should manage its own memory by using copy semantics for any setter method implementation.n - Default behavior: If not specified, 'assign' is assumed.n - When to use: Use 'assign' when setting simple types like NSNumber, NSString, or BOOL, which are immutable and do not require retaining.
2. 'retain': It implies that the property should retain its value during its lifetime.n - When to use: Use 'retain' when setting objects that can be mutated, like custom classes or collections.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Apple iOS Interview Questions

How core data works to save data in persistent storage?

1 Answers  


What is App Bundle?

1 Answers  


Explain how app delegate is declared by Xcode project templates?

1 Answers  


Explain why delegates and notifications are different.

1 Answers  


What is difference between category and extension in ios?

1 Answers  


What is singleton in ios swift?

1 Answers  


What ios version onwards arc can be used?

1 Answers  


Describe what “app thinning” means ?

1 Answers  


What coding language is used for ios apps?

1 Answers  


How many bytes we can send to apple push notification server?

1 Answers  


What is dynamic typing in iOS operating system?

1 Answers   CDC,


What are the ios devices?

1 Answers  


Categories