Normally I'm use 'property' outlets and variables only if it's access by another class. Otherwise it's declare within interface block. But I saw some are create 'property' outlet and variables but they are not access these in another class. So any one can explain, if we not access some outlet or variable from another class why we need 'property' outlets and variables?
-
http://stackoverflow.com/questions/14236799/should-i-declare-variables-in-interface-or-using-property-in-objective-c-arc – Balu Jul 17 '13 at 06:50
3 Answers
They were declared so that they would be exposed in the NIB/XIB editor (aka Interface Builder).
This allows you to associate views to the object's properties in the NIB editor, and the XIB unarchiver will set the properties when initialized so that you may easily reference those instances from your class once initialized.

- 104,054
- 14
- 179
- 226
If you don't need to access the outlet from another class, you don't need to make it a property. You can make it an instance variable in your @implementation
:
@implementation ViewController {
IBOutlet UIView *someView;
}
...
Some people don't like using plain instance variables and prefer to always use properties, even for private data. It is particularly useful to use properties instead of raw instance variables if you are not using ARC, because you can rely on property setters to retain and release their objects. If you are using ARC, this is not an issue.
If you want to use a property but you don't want to declare the property in your @interface
, you can put a class extension at the top of your .m
file (above your @implementation
), and put the property there:
@interface ViewController () {
@property (nonatomic, strong) IBOutlet UIView *someview;
@end
@implementation ViewController
...

- 375,296
- 67
- 796
- 848
I think you are asking about Properties. Properties are used to facilitate you writing getters and setters.
Why do we need getters setters? to have one place from where we can access a variable so that in future if we need to add some rule we can do it without changing whole code.
this question is covered indepth in Why use getters and setters?
Outlets are for interfacebuilder to access properties.

- 1
- 1

- 2,799
- 2
- 27
- 41