Search code examples
iphoneobjective-cnslog

format not a string literal and no format arguments (not involving NSLog)


(I am new to objective c so apologies if this seems to be a simple question)

I researched the following message here

format not a string literal and no format arguments

and most of the responses involve an NSLog statement. However, my error shows up with this line

NSString *path = [[self applicationDocumentsDirectory] stringByAppendingFormat:[NSString stringWithFormat:@"/%@", [managedObject Name]]];

I am troubleshooting a set of code and don't seem to understand why the error is occuring here. any assistance on this would be appreciated.


Solution

  • The below should fix it.

    NSString *path = [[self applicationDocumentsDirectory] stringByAppendingFormat:[NSString stringWithFormat:@"/%@", [managedObject Name]], nil];
    

    Alternatively

    NSString *path = [[self applicationDocumentsDirectory] stringByAppendingFormat:@"/%@", [managedObject Name]];
    

    Should also do it.

    You were calling two methods that expected a format parameter, you were passing one into the [NSString stringWithFormat] but not the stringByAppendingFormat method.