1

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?

adit
  • 32,574
  • 72
  • 229
  • 373
  • 2
    The default for the properties is assign. See:[this link](http://stackoverflow.com/questions/805972/is-assign-the-default-setup-of-the-property-compiler-directive) And for more informations: [this link](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html) – Daniel Oct 18 '12 at 22:19

1 Answers1

2

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.

deleted_user
  • 3,817
  • 1
  • 18
  • 27