简体   繁体   中英

default property declaration in non-ARC project

What is the default property value if I just do the following:

@property (nonatomic) UIButton *myButton;

in a non-ARC project. Is this retain or assign?

Since in non-ARC projects of any size its pretty important to see exactly whats retained and assigned or copied, I would really recommend not using that default.

Its hard to read when your looking at a class with several properties that may have many other attributes such as readonly, atomic and non atomic. getter= etc

Although its not perfect putting a #define in a constant header like

#define ASSIGN nonatomic, assign
#define RETAIN nonatomic, retain

for your most common usages can make your property definitions a little more explicit so that when you eventually catch up to writing your dealloc methods its a really quick check to see what you need to release.

Most of my property definitions looks like

@property (ASSIGN) Foo* foo; 

or

@property (RETAIN) Foo* foo;

Thats what I do and it keeps the noise on property definitions down and makes the code read a little easier when troubleshooting or perfecting manual memory managed apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM