Return to Snippet

Revision: 60055
at October 18, 2012 07:56 by kutyadog


Updated Code
//----------------------------------
//  Person.h

#import <Foundation/Foundation.h>

@interface Person : NSObject {
    int age;
    int weight;
}
-(void) print;
-(void) setAge: (int) a;
-(void) setWeight: (int) w;
@end



//----------------------------------
//  Person.m
//  codeTester

#import "Person.h"

@implementation Person
-(void) print{
    NSLog(@"I am %i years old and weight %i pounds", age, weight);
}
-(void) setAge: (int) a{
    age=a;
}
-(void) setWeight: (int) w{
    weight=w;
}
@end



//----------------------------------
//how to call

#import "Person.h"      //dont forget to import it

Person *bucky;
bucky = [Person alloc]; //give it memory
bucky = [bucky init];   //allows us to defualt init metod
[bucky setAge:23];
[bucky setWeight:350];
[bucky print];

Revision: 60054
at October 18, 2012 07:40 by kutyadog


Initial Code
//----------------------------------
//  Person.h
//  codeTester
//
//  Created by CHRISTOPER JOHNSON on 1/20/12.
//  Copyright (c) 2012 Bay Area News Group. All rights reserved.

#import <Foundation/Foundation.h>

@interface Person : NSObject {
    int age;
    int weight;
}
-(void) print;
-(void) setAge: (int) a;
-(void) setWeight: (int) w;
@end



//----------------------------------
//  Person.m
//  codeTester
//
//  Created by CHRISTOPER JOHNSON on 1/20/12.
//  Copyright (c) 2012 Bay Area News Group. All rights reserved.
//

#import "Person.h"

@implementation Person
-(void) print{
    NSLog(@"I am %i years old and weight %i pounds", age, weight);
}
-(void) setAge: (int) a{
    age=a;
}
-(void) setWeight: (int) w{
    weight=w;
}
@end



//----------------------------------
//how to call

#import "Person.h"      //dont forget to import it

Person *bucky;
bucky = [Person alloc]; //give it memory
bucky = [bucky init];   //allows us to defualt init metod
[bucky setAge:23];
[bucky setWeight:350];
[bucky print];

Initial URL


Initial Description
Example of how to build and call a class or object

Initial Title
xcode Objective C - build class / objects

Initial Tags
class, object

Initial Language
Objective C