Search code examples
objective-cpropertiesiboutletdeclare

Difference between declaring IBoutlet depending on where it declare


We can declare like this for IBOutlet. Can I know what is the difference/advantages between 1 and 2 declaring method style?

@interface CurrentJobDetailsVC ()
{
    IBOutlet UISegmentedControl *segControl; // -> 1 
}
@property (weak, nonatomic) IBOutlet UISegmentedControl *segControl; // -> 2 

@end

Solution

  • This is globally the same expect 2 differences:

    1 - Declare an iVar.

    • IBOutlet UISegmentedControl *segControl; is equivalent to __strong IBOutlet UISegmentedControl *segControl;
    • You only have an iVar and you can access it using [segControl someMethod].

    2 - Declare it as a property

    • You have a property self.segControl and you can use it like [self.segControl someMethod]
    • You also have an iVar and you can use it like [_segControl someMethod]