Skip to content
Alfie Hanssen edited this page Nov 20, 2013 · 1 revision

Create a new NSObject subclass named Tree:

Create a New Class

New Class Info

Your New Class

Any class that we create will take advantage of inheritance.

NSObject Class Ref

###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
Clone this wiki locally