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?
%s
is meant for C strings. You should use %@
instead of %s
to output NSString
(and other Foundation types) to NSLog
.
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