没有错误,但NSLog没有输出

时间:2013-02-27 10:52:17

标签: objective-c nslog

我正忙着在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];
    }


}

3 个答案:

答案 0 :(得分:4)

print位于return之后,此代码永远不会到达。

答案 1 :(得分:2)

写回车和返回声明上面的所有代码。

答案 2 :(得分:0)

替换它: -

int main (int argc, char * argv[])
{
    @autoreleasepool {



        // 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];

        return UIApplicationMain(argc, argv, nil, NSStringFromClass([JTAppDelegate class]));

    }


}