Zhe*_*hen 26 debugging xcode objective-c nslog
我的Xcode中有以下代码片段:
NSString *digit [[sender titlelabel] text];
NSLog([digit]);
Run Code Online (Sandbox Code Playgroud)
我试图构建应用程序,并获得该行的以下警告消息 NSLog([digit]);
Warning: Format not a string literal and no format arguments
Run Code Online (Sandbox Code Playgroud)
你能告诉我如何解决这个警告信息吗?这个消息究竟意味着什么?
Eim*_*tas 50
试试这段代码:
NSString *digit = [[sender titlelabel] text];
NSLog(@"%@", digit);
Run Code Online (Sandbox Code Playgroud)
该消息表示您使用该digit变量的语法不正确.如果您没有发送任何消息 - 您不需要任何括号.
Fab*_*oni 25
使用NSLog()这样:
NSLog(@"The code runs through here!");
Run Code Online (Sandbox Code Playgroud)
或者像这样 - 使用占位符:
float aFloat = 5.34245;
NSLog(@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat);
Run Code Online (Sandbox Code Playgroud)
在NSLog()你可以使用它像+ (id)stringWithFormat:(NSString *)format, ...
float aFloat = 5.34245;
NSString *aString = [NSString stringWithFormat:@"This is my float: %f \n\nAnd here again: %.2f", aFloat, aFloat];
Run Code Online (Sandbox Code Playgroud)
您也可以添加其他占位符:
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);
Run Code Online (Sandbox Code Playgroud)
为什么会有括号digit?它应该是
NSLog("%@", digit);
您还缺少=第一行中的...
NSString *digit = [[sender titlelabel] text];
| 归档时间: |
|
| 查看次数: |
121974 次 |
| 最近记录: |