没有错误,但NSLog没有输出

时间:2021-04-25 19:59:14

I am busy doing a test program in Xcode. So far I have this code in main.m. I get no errors at all, but the output isnt happening i.e NSLog in the print method.

我正忙着在Xcode中做一个测试程序。到目前为止,我在main.m中有这段代码。我没有任何错误,但输出没有发生,即打印方法中的NSLog。

What could be the problem? I know I must be missing something obvious.

可能是什么问题呢?我知道我必须遗漏一些明显的东西。

#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 个解决方案

#1


4  

your printis after a return, this code is never reached.

返回后你的printis,永远不会到达此代码。

#2


2  

Write Print and all code above return statement.

Write print和上面返回语句的所有代码。

#3


0  

Replace this :-

替换这个: -

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

    }


}

#1


4  

your printis after a return, this code is never reached.

返回后你的printis,永远不会到达此代码。

#2


2  

Write Print and all code above return statement.

Write print和上面返回语句的所有代码。

#3


0  

Replace this :-

替换这个: -

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

    }


}