测试对象类是否为零的最佳方法?

Dav*_*ave 0 objective-c

在目标C中,有什么更好的方法:

if ([response class] == [nil class])
Run Code Online (Sandbox Code Playgroud)

response是NSDictionary或NSMutableDictionary

代码正在运行,但我收到了"Invalid receiver type 'void *' or "comparison of distinct Objective-C types 'Class' and 'struct NSMutableDictionary *' lacks a cast"警告消息

谢谢

Sam*_*hie 6

如果你真的想要测试[response class],而不是response自己的价值,你会想要使用

if ([response isKindOfClass:[NSNull class])
Run Code Online (Sandbox Code Playgroud)

如果你想检查response自己是否是nil,我在这个问题的答案中描述了一个很好的方法.