Alright, following your clarification, I'll try to explain what's going on there.
Let's say you have this in your header (.h) file:
@interface Foobar {
}
@property (readonly) int numberOfPies;
@end
This define's a class's public interface. While I've said "public" there, I want to make it perfectly clear that Objective-C does not have the same concept of visibility that Java or C++ have (it employs it for instance variables, but that's the farthest it goes that I'm aware of). I've also bolded "class" because there's an important distinction coming up. The other thing I want to point out is that the class publicly declares the numberOfPies
to be readonly
, since that's also going to be important.
Now, let's look at the implementation (.m) file for this class:
@interface Foobar ()
- (void) doSomething;
@property (readwrite) numberOfPies;
@end
@implementation Foobar
@synthesize numberOfPies;
- (void) doSomething {
NSLog(@"Doing something");
}
@end
Look at @interface Foobar ()
— this begins a class extension. It is not a class declaration. These are also sometimes called private categories, anonymous categories, or class continuations (according to zneak in a comment below), but the important thing to know is that they're basically a kind of category (I've linked to Apple's documentation on categories). These essentially define additional methods and properties and can be applied to any class whatsoever. They're used here is to provide what amounts to a private interface for the class (hence "private category").
Moving on, now we'll compare the numberOfPies
property between the class and the category. If you didn't notice the difference yet, here it is: the class exposes it as readonly
, the category expands this and makes it readwrite
inside the implementation. When synthesizing the property, Obj-C will include both the getter and setter if this happens. The important thing here is that, aside from whether your property is readonly
or readwrite
, your property cannot change. It can't have the assign
attribute in the class and copy
in the category. This basically lets you define a convenient private setter for properties as well.
One important thing to note here is that absolutely nothing in that category is truly private. Nothing can stop you from sending the doSomething
message to a Foobar
object, though the compiler will give you a warning outside of the class's implementation file.
Following that, you have your standard implementation. This includes implementations for the methods in your anonymous category.