-1
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]];

some answers that I've tried and didn't help are listed below. any help would be appreciated

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

Community
  • 1
  • 1
lizzy81
  • 97
  • 1
  • 12
  • did u really look into them? those links really have your issue solved. – Teja Nandamuri Jan 06 '16 at 15:05
  • i did, however i didn't know what i was looking for, i now know that `stringByAppendingFormat` and `stringByAppendingString` exists. i read the second link comparing each line and didn't notice the difference until @leejay mentioned it – lizzy81 Jan 06 '16 at 19:50

1 Answers1

1

You don't appear to be appending a format, but rather appending a string, which is probably why the compiler is complaining. Try using stringByAppendingString like so

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

and it should work. Or, if you really want to use stringByAppendingFormat, do it like so:

NSString *file = [documentDirectory stringByAppendingFormat:@"/%@.pdf", _idNo];
Leejay Schmidt
  • 1,138
  • 1
  • 14
  • 24
  • i went with the `format` option, if i understand this correctly, `stringByAppendingFormat` is equivalent to nesting `stringByAppendingString` and `stringWithFormat`? if thats the case, thats good to know. thanks for the help – lizzy81 Jan 06 '16 at 15:09
  • I think you've got it. `stringByAppendingString` concatenates the input `string` with the existing `string`, but said input `string` must be a `string literal`. `stringByAppendingFormat` first builds the `string` from the defined `format` (a `string` with arguments, such as the `%@`), and then concatenates the newly built `string literal` with the existing `string`. – Leejay Schmidt Jan 06 '16 at 15:16