Using NSLog for debugging

前端 未结 6 2210
暗喜
暗喜 2020-12-16 10:02

I have the following code snippet in my Xcode:

NSString *digit [[sender titlelabel] text];
NSLog([digit]);

I tried to build the application

6条回答
  •  粉色の甜心
    2020-12-16 10:45

    Use NSLog() like this:

    NSLog(@"The code runs through here!");
    

    Or like this - with placeholders:

    float aFloat = 5.34245;
    NSLog(@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat);
    

    In NSLog() you can use it like + (id)stringWithFormat:(NSString *)format, ...

    float aFloat = 5.34245;
    NSString *aString = [NSString stringWithFormat:@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat];
    

    You can add other placeholders, too:

    float aFloat = 5.34245;
    int aInteger = 3;
    NSString *aString = @"A string";
    NSLog(@"This is my float: %f \n\nAnd here is my integer: %i \n\nAnd finally my string: %@", aFloat, aInteger, aString);
    

提交回复
热议问题