开发者

Objective C - Calling a static method on a Class type object?

I get the following error: Class is not an object开发者_如何学JAVAive c class name

- (void)CallStaticMethodForClass :(Class *)myClass
{
     [myClass doSomething];
}

+ (void)doSomething
{
     //
}


It should be declared as:

- (void)callMethodOnClass:(Class)myClass { ...

A couple things:

  1. The pointer (*) is unnecessary when referring to a Class. Command-double click "Class" to see why (it's part of the typedef)
  2. We don't start our methods with a capital letter
  3. There's no such thing as a "static" method in Objective-C. We have "class methods".
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜