DataController.h
@class Play;
@interface DataController : NSObject
- (unsigned)countOfList;
- (Play *)objectInListAtIndex:(unsigned)theIndex;
@end
DataController.m
#import "DataController.h"
#import "Play.h"
@interface DataController ()
@property (nonatomic, copy, readwrite) NSMutableArray *list;
- (void)createDemoData;
@end
@implementation DataController
@synthesize list;
- (id)init {
if (self = [super init]) {
[self createDemoData];
}
return self;
}
Why do you think that @interface is defined twice? And also whats the meaning of ()? Shouldn’t there be a class name maybe the super class between the parentheses?
In general, the syntax
@interface ClassName (CategoryName)is for declaring a category. Categories are a way to add methods to a class. You can do this even with classes for which you don’t have the source code. See more here.@interface ClassName ()(with nothing in the parentheses) is essentially a special case of a category and is called a class extension. The primary difference between a class extension and a category is that methods declared in a class extension must be defined/implemented in the main @implementation block for the class, or you’ll get a compiler warning. Methods in a regular category can be defined in an external @implementation block.The most common use for class extensions (as in this case) is for declaring private methods. Objective-C doesn’t have support for true private methods, so an easy way to accomplish the same basic end result is to declare private methods in a class extension at the top of the .m file. Since these methods aren’t defined in the .h file, other classes won’t see them, and you’ll get a compiler warning if you try to use them outside the class they belong to.
You can also redeclare a readonly @property as readwrite in a class extension. That way, code external to the class implementation can only read a property’s value, but inside the class’s implementation, you can write to it too. This is the only case where it’s allowable to redeclare an @property.
(Note that class extensions were a new feature in Objective-C 2.0 and aren’t available on Mac OS X 10.4 and earlier.)