Changes in iOS5 @property

In iOS 5, save and release are no longer supported. Instead, β€œstrong” and β€œweak” is a new way.

IOS 4 Code:

@property(nonatomic, retain) @property(nonatomic, assign) 

IOS 5 code:

 ??? ??? 
+6
source share
3 answers

"In iOS 5, saving a release is no longer supported." They are simply not using ARC.

When using ARC -[<NSObject> retain] is non-op.

For properties, you can use strong if you use ARC, but this is not required (you can use retain too if you want). strong and retain identical:

 @property(nonatomic, strong) @property(nonatomic, assign) 

Just make sure you are compatible (do not use both strong and retain in the same project).

+12
source

They are not exactly the same, but basically retain := strong and assign := weak I would suggest taking a look at ARC Release Notes

+5
source

nonatomic property claims that the object is not thread safe, which means that another thread is trying to access this object, than bad things can happen, but it is much faster than an atomic property.

strong used with ARC, and it basically helps you without worrying about saving the number of objects. ARC automatically releases it for you when you are done with it. Using the strong keyword means that you own the property.

weak property means that you do not own it, and it simply keeps track of the object until the object to which it was assigned remains, as soon as the second object is released, it loses value. E.g. obj.a=objectB; is used, and a has a weak property, than its value will be valid only until the object B remains in memory.

copy property is very well explained here fooobar.com/questions/25407 / ...

strong,weak,retain,copy,assign are mutually exclusive, so you cannot use them on the same object ... read the Declared Properties section of http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual /ObjectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW1

hoping this helps you a little ...

+4
source

Source: https://habr.com/ru/post/903408/


All Articles