I am having trouble converting arguments to NSString format for my Cocoa application. I start my application like so:
open my.app --args a1 a2
I try to access the arguments like so:
const char *h_path_char = [[[[NSProcessInfo processInfo] arguments] objectAtIndex:1] fileSystemRepresentation];
const char *s_path_char = [[[[NSProcessInfo processInfo] arguments] objectAtIndex:2] fileSystemRepresentation];
NSString *h_path = [NSString stringWithUTF8String:h_path_char];
NSString *s_path = [NSString stringWithUTF8String:s_path_char];
NSLog(@"%s", h_path);
NSLog(@"%s", s_path);
However, Xcode complains about the NSLog with the following warning:
Conversion specifies type “char” but the argument has type “NSString”.
How can I overcome this?
%sis meant for C strings. You should use%@instead of%sto outputNSString(and other Foundation types) toNSLog.