格式字符串不是字符串文字(以前的解决方案没有帮助)

时间:2016-01-06 14:56:20

标签: xcode nsstring

NSData *pdfURL = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_paperURL]]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [paths objectAtIndex:0];

//line with error
NSString *file = [documentDirectory stringByAppendingFormat:[NSString stringWithFormat:@"/%@.pdf", _idNo]];
//ive also tried adding nil at the end
NSString *file = [documentDirectory stringByAppendingFormat:[NSString stringWithFormat:@"/%@.pdf", _idNo, nil]];
下面列出了我尝试过但没有帮助的一些答案。任何帮助将不胜感激

Warning : Format string is not a string literal (potentially insecure)

http://iphonedevsdk.com/forum/iphone-sdk-development/107828-format-string-is-not-a-string-literal-potentially-insecure-how-to-avoid-this.html

Issue With Code: Format string is not a string literal

1 个答案:

答案 0 :(得分:1)

您似乎没有附加format,而是附加string,这可能是编译器抱怨的原因。尝试使用stringByAppendingString,如此

NSString *file = [documentDirectory stringByAppendingString:[NSString stringWithFormat:@"/%@.pdf", _idNo]];

它应该有效。或者,如果您真的想使用stringByAppendingFormat,请执行以下操作:

NSString *file = [documentDirectory stringByAppendingFormat:@"/%@.pdf", _idNo];