将char转换为NSString

Abs*_*Abs 2 cocoa objective-c

我无法将参数转换为我的Cocoa应用程序的NSString格式.我这样启动我的应用程序:

open my.app --args a1 a2
Run Code Online (Sandbox Code Playgroud)

我尝试访问这样的参数:

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);
Run Code Online (Sandbox Code Playgroud)

但是,Xcode抱怨NSLog以下警告:

转换指定类型"char",但参数的类型为"NSString".

我怎么能克服这个?

ayo*_*yoy 9

%s适用于C字符串.您应该使用%@而不是%s输出NSString(和其他Foundation类型)NSLog.