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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:48:01  来源:igfitidea点击:

Data argument not used by format string

iosobjective-ccxcode

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

scorereturns integer so %ior %dshould 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 %iinstead of @i:

格式字符串应该使用%i而不是@i

NSLog(@"The score is %i", [p score]);