I am fairly new to objective-c and am having trouble understanding the warning message for the following block of code:
void PrintPathInfo() {
NSString *path = @"~";
NSString *message = @"My home folder is: ";
NSLog([message stringByAppendingString: [path stringByExpandingTildeInPath]]);
}
This is the warning message I am getting for the last line (call to NSLog):
warning: format not a string literal and no format arguments
Can someone please clarify? Is this a warning message I should be concerned about?
Thanks.
Your code should work just fine, but could misbehave if there are any '%' formatting characters in the passed string--that could confuse NSLog. For example, try swapping this into your code:
NSString *message = @"My home %folder is: ";
NSLog will interpret that '%f' in a bad way.
You can avoid the warning (and the danger), by using a string literal with formatting and passing in your strings, like this:
NSLog(@"%@%@", message, [path stringByExpandingTildeInPath]);
You might also check this link:
http://www.cocoabuilder.com/archive/message/cocoa/2009/8/29/243819
Good luck!
If you want to write the output to nslog you need something like this:
NSLog(@"My home folder is %@",[path stringByExpandingTildeInPath]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With