我搞不懂为什么我会
use of undeclared identifier _cmd did you mean rcmd在NSAssert所在的线路上。
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int x = 10;
NSAssert(x > 11, @"x should be greater than %d", x);
[pool drain];
return 0;
}发布于 2012-03-16 23:18:45
在每个Objective-c方法中,都有两个隐藏变量id self和SEL _cmd
所以
- (void)foo:(id)bar;是真的
void foo(id self, SEL _cmd, id bar) { ... }当你打电话给
[someObject foo:@"hello world"]它实际上是
foo( someObject, @selector(foo), @"hello world")如果您cmd-单击NSAssert跳转到它的定义,您将看到它是一个宏,它使用了您从中调用它的方法的隐藏_cmd变量。这意味着如果你不在Objective-c方法中(也许你在‘main’中),因此你没有_cmd参数,你就不能使用NSAssert。
相反,您可以使用替代的NSCAssert。
发布于 2012-03-16 23:08:49
NSAssert is only meant to be used within Objective-C methods.由于main是一个C函数,因此请改用NSCAssert。
发布于 2012-03-16 23:01:56
尝试替换
NSAssert(x > 11,NSString字符串格式:@“x应大于%d",x);
使用
NSCAssert(x > 11,NSString字符串格式:@“x应大于%d",x);
https://stackoverflow.com/questions/9739460
复制相似问题