2012-02-29 111 views
0

我无法将参数转换为我的Cocoa应用程序的NSString格式。我开始我的应用程序,像这样:将char转换为NSString

open my.app --args a1 a2 

我尝试访问像这样的论点:

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); 

然而,Xcode的埋怨NSLog以下警告:

转换指定键入“char”,但参数的类型为“NSString”。

我该如何克服这一点?

+3

不应该是'NSLog(@“%@”,h_path);'? – 2012-02-29 17:26:25

+0

@Robert,是的,或者用'%s'打印原始'const char *'。 – mpontillo 2012-02-29 17:27:23

回答

5

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

+0

谢谢ayoy--我犯了一个菜鸟的错误。 – Abs 2012-02-29 18:53:14