-
Notifications
You must be signed in to change notification settings - Fork 3
Objc: Classes
Alfie Hanssen edited this page Nov 20, 2013
·
1 revision
Create a new NSObject
subclass named Tree
:
Any class that we create will take advantage of inheritance.
###The Interface File
In Tree.h
:
@interface Tree : NSObject
@property (nonatomic, strong) NSString *species;
@property (nonatomic, assign) int age;
- (id)initWithSpecies:(NSString *)species age:(int)age;
- (void)printInfo;
@end
###The Implementation File
In Tree.m
:
@implementation Tree
- (id)initWithSpecies:(NSString *)species age:(int)age
{
self = [super init];
if (self) {
self.species = species;
self.age = age;
}
return self;
}
- (void)printInfo
{
NSLog(@"This %@ tree is %i years old.", self.species, self.age);
}
@end