我正忙着在 Xcode 中做一个测试程序。到目前为止,我在 main.m 中有这段代码。我根本没有收到任何错误,但输出没有发生,即打印方法中的 NSLog。
可能是什么问题呢?我知道我一定遗漏了一些明显的东西。
#import <UIKit/UIKit.h>
#import "JTAppDelegate.h"
@interface Fraction: NSObject
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@end
@implementation Fraction
{
int numerator;
int denominator;
}
-(void) print
{
NSLog (@"%i/%i", numerator, denominator);
}
-(void) setNumerator:(int)n
{
numerator = n;
}
-(void) setDenominator:(int)d
{
denominator = d;
}
@end
int main (int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([JTAppDelegate class]));
// Create an instance of Fraction and initialise it
Fraction *myFraction = [[Fraction alloc] init];
//Set Fraction to 1/3
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
//Display the fraction using the print method
[myFraction print];
}
}