需要帮助解决Objective-c简单程序输出

时间:2012-12-28 01:28:45

标签: objective-c

#import <Foundation/Foundation.h>

@interface engine : NSObject

@end




#import "engine.h"

@implementation engine

-(NSString *)discription{
    return (@"I am an engine");
}
@end



#import <Foundation/Foundation.h>

@interface tire : NSObject

@end



#import "tire.h"

@implementation tire
-(NSString *)description{
    return (@"I am a tire, I last for a while");
}
@end




#import <Foundation/Foundation.h>
#import "tire.h"
#import "engine.h"
@interface car : NSObject{
    engine *eng;
    tire *tir[4];
}
-(void)print;
@end




#import "car.h"

@implementation car

-(id)init{
    if(self ==[super init]){
        eng=[engine new];
        tir[0]=[tire new];
        tir[1]=[tire new];
        tir[2]=[tire new];
        tir[3]=[tire new];

    }
    return (self); 
}
-(void)print{
    NSLog(@"%@",eng);
    NSLog(@"%@",tir[0]);
    NSLog(@"%@",tir[1]);
    NSLog(@"%@",tir[2]);
    NSLog(@"%@",tir[3]);
}

@end









#import <UIKit/UIKit.h>
#import "car.h"


int main(int argc, char *argv[])
{
    car *ca;
    ca=[car new];
    [ca print];
    return (0);

}

//在Xcode上运行程序时输出结果:

// 2012-12-27 00:55:31.241 CarProject [9341:f803]引擎:0x686d990

// 2012-12-27 00:55:31.244 CarProject [9341:f803]我是一个轮胎,我会坚持一段时间

// 2012-12-27 00:55:31.245 CarProject [9341:f803]我是一个轮胎,我会坚持一段时间

// 2012-12-27 00:55:31.246 CarProject [9341:f803]我是个轮胎,我会坚持一段时间

// 2012-12-27 00:55:31.246 CarProject [9341:f803]我是个轮胎,我会坚持一段时间

//因此引擎无法正确输出字符串。我需要帮助。谢谢。

1 个答案:

答案 0 :(得分:6)

您拼错了Engine类的描述方法的名称:它应该是description,而不是discription