Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting char into NSString

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?

like image 570
Abs Avatar asked Oct 14 '25 19:10

Abs


1 Answers

%s is meant for C strings. You should use %@ instead of %s to output NSString (and other Foundation types) to NSLog.

like image 184
ayoy Avatar answered Oct 17 '25 11:10

ayoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!