xcode 格式字符串未使用数据参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14942308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Data argument not used by format string
提问by Try to be a success
following the videos on lynda's objective c i've ran intro a small problem,
按照 lynda 的目标 c 上的视频,我遇到了一个小问题,
#import <Foundation/Foundation.h>
#import "Player.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Player *p = [[Player alloc] init];
NSLog(@"The score is @i", [p score]); <-- Data argument not used by format string
}
return 0;
}
回答by rmaddy
You don't have a valid format string. You want %i
, not @i
.
您没有有效的格式字符串。你想要%i
,没有@i
。
回答by Anoop Vaidya
Use NSLog(@"The score is %i", [p score]);
用 NSLog(@"The score is %i", [p score]);
score
returns integer so %i
or %d
should be used not @i
score
返回整数所以%i
或%d
不应该使用@i
回答by nkongara
If value returned by [p score] is an integer then it should be
NSLog(@"The score is %i", [p score]); // Always use '%' as format specifier not '@'
如果 [p score] 返回的值是一个整数,那么它应该是
NSLog(@"The score is %i", [p score]); // 始终使用 '%' 作为格式说明符而不是 '@'
回答by leorleor
The format string should use %i
instead of @i
:
格式字符串应该使用%i
而不是@i
:
NSLog(@"The score is %i", [p score]);