Best way to define private variables in Objective-C

objective-c

Solution

The "Modern Objective-C" way to do this is to declare them in your implementation block, like this:

@implementation ClassName {
    int privateInteger;
    MyObject *privateObject;
}

// method implementations etc...

@end

See this earlier post of me with more details.

Problem

I want to define private instance variables in MyClass.m file. It seems to me there are two ways to do it: use class extension ``` @interface HelloViewController () { int value; } ``` define in @implementation section ``` @implementation HelloViewController { int value; } ``` Which is better? I think recent Apple's coding style is to use class extension? e.g. MasterViewController.m generated by 'Master-Detail Application Template' ``` @interface MasterViewController () { NSMutableArray *_objects; } @end ```

Original source

Related problems