djeddiej
djeddiej

Reputation: 106

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.

Upvotes: 2

Views: 1491

Answers (4)

Eiko
Eiko

Reputation: 25632

Beside what the others have said, you should look into

- (NSString *)stringByAppendingPathComponent:(NSString *)aString

Upvotes: 3

euphoria83
euphoria83

Reputation: 15136

[NSString stringWithFormat:@"/%@", [managedObject Name]

will return a string with the %@ already replaced by the value of [managedObject Name]. Therefore, the method stringByAppendingFormat is not getting the formatting string and any arguments.

BTW, the convention is to use method names beginning with lowercase alphabets, unlike in [managedObject Name]

Upvotes: 0

Skyler
Skyler

Reputation: 612

You are using stringByAppendingFormat, and then using stringWithFormat. Pick one or the other. Fix:

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

Upvotes: 1

acqu13sce
acqu13sce

Reputation: 3809

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.

Upvotes: 4

Related Questions