class分成两部分,一个是interface,一个是implementation
@interface ClassName : ItsSuperclass
// Method and property declarations.
@end
+ alloc; // Class method, 没有返回数值,默认是id
- (void)setRadius:(float)aRadius; // instance method
@property (attributes) Type propertyName;
instance variables(大括号内的都是instance variable,这些变量都是私有的)
@interface ClassName : ItsSuperclass
{
// Instance variable declarations.
}
// Method and property declarations.
@end
class的声明,声明之后就不需要再import文件了,这个和C++非常类似。
@interface Sibling : NSObject
{
Sibling *twin;
int gender;
struct features *appearance;
}
- makeIdenticalTwin
{
if ( !twin ) {
twin = [[Sibling alloc] init];
twin->gender = gender; // 访问他本身就使用->
twin->appearance = appearance;
}
return twin;
}
@interface Worker : NSObject
{
char *name;
@private
int age;
char *evaluation;
@protected
id job;
float wage;
@public
id boss;
}
[self setOrigin:someX :someY];
[super setOrigin:someX :someY];