Senor_Wilson
Senor_Wilson

Reputation: 47

Objective-c: Now allowing me to create an instance of a class

I just started programming in objective-c(today) and I'm just doing some simple command line examples but I've already run into something that has stumped me. I am getting a compiler error on lines 5 & 6 in main. Here is my code:

Fraction Interface:

#import <Foundation/Foundation.h>

@interface Fraction : NSObject
{
    int numerator, denominator; 
}

-(void)print; 
-(void)setDenominator; 
-(void)setNumerator; 

@end

Fraction implementation:

#import "Fraction.h"

@implementation Fraction
-(void)print {
    NSLog(@"%i/%i",numerator,denominator); 
}

-(void)setNumerator: (int) n {
    numerator = n; 
}

-(void)setDenominator: (int) d {
    denominator = d; 
}

@end

Main:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    @autoreleasepool {
        Fraction  *f1 = [[Fraction alloc] init]; 
        Fraction  *f2 = [[Fraction alloc] init];
    }
    return 0;
}

All 3 files are in the same folder. I'm using Xcode; if this is relevant information.

Upvotes: 0

Views: 76

Answers (1)

Joshua Weinberg
Joshua Weinberg

Reputation: 28688

Looks like you forgot to add #import "Fraction.h" to the top of main.m, In the future adding the error you receive would be helpful.

Upvotes: 2

Related Questions