0

Prior to ARC I would declare IBOulets in the header as follows:

- (IBOutlet) UIButton * aButton

@property (nonatomic, retain) IBOutlet UIButton * aButton;

Then in the .m file

@synthesize aButton;

What is the equivalent correct way of doing the above under arc ? Would I just declare :

@property (weak)IBOutlet UIButton * aButton ?

Thanks.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113
  • here's a better answer to your question http://stackoverflow.com/questions/7678469/should-iboutlets-be-strong-or-weak-under-arc – Nitin Alabur Jul 24 '12 at 14:41
  • the documentation says you should use `strong` pointers for the outlets, but if you use `weak` or `unsafe_unretained` pointers for the static outlets inside the `UIView`, which is caught with `strong` pointer as well, you won't have any problem in the future. – holex Jul 24 '12 at 14:43
  • You used to declare IBOutlet's like that...? – TheAmateurProgrammer Jul 24 '12 at 14:58

2 Answers2

3
@property (strong)IBOutlet UIButton *aButton
beyerss
  • 1,302
  • 3
  • 21
  • 38
1

There are some circumstances where you may want to vary the strong/weak attribute. Have a look at: Should IBOutlets be strong or weak under ARC?

enter image description here

Community
  • 1
  • 1
Ian L
  • 5,553
  • 1
  • 22
  • 37
  • Yeah thanks - I read that but am unsure what is meant by "Top level objects which link to the files owner" – GuybrushThreepwood Jul 24 '12 at 14:46
  • 1
    mattjgalloway's comment summarises that concept: "it means objects in the NIB that are at the root level, i.e. say you instantiated another view in there which isn't directly a subview of the main view, then it needs to have a strong reference." When you look at a NIB's objects in Interface Builder, most of them are nested below the main View. These can be weak referenced. If you have any other views at the root level, then these need to be strong referenced. – Ian L Jul 24 '12 at 14:56