views:

212

answers:

5

Objective-C for iPad, Where do you put IBOutlet? In instance variable decleration or @property decleration? Is there a difference at all?

+3  A: 

Both are valid, even if it's usually recommended to put it on a property.

The difference with a property is that it's available from the outside, and that getter/setter methods are used.
That also allows property qualifiers, like non-atomic and retain, usually set for the IBOutlets.

Macmade
A: 

I do both, and synthesise it in the .m file. I'm not 100% that they're both essential, but it doesn't hurt.

Dyldo42
Just don't do this...
Macmade
How about explaining your position, Macmade? I see a ton of code in the ethos that applies IBOutlet to both.
Jasconius
+4  A: 

IBOutlet can be a marker on ivars or a property declaration.

There is a slight difference. IBOutlet properties go through access methods whereas IBOutlet ivars are direct ivar access.

The major difference is that if the IBOutlet property is retained, you'll have to release it in -dealloc whereas you typically need not do anything with an IBOutlet ivar. The upside of IBOutlet property is that you get all the useful features of properties.

Giao
Not correct for the retain part. IBOutlet has nothing to do with it. The property will be retained only if you specify it with the 'retain' qualifier. But you could also specify 'assign' instead. Then the property won't be retained when set!
Macmade
Please note the "if" in that statement.
Giao
My mistake, sorry : )
Macmade
+1  A: 

Both are valid I suggest you to use @property

Kishore
+1  A: 

mmalc (who is definitely a reputable source) says that the current best-practice is putting it on the @property declaration. He gives details (along with some cavets) in his answer to this quiestion

Kelan