开发者

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

开发者 https://www.devze.com 2023-02-08 04:36 出处:网络
I get the following error: Class is not an object开发者_如何学JAVAive c class name - (void)CallStaticMethodForClass :(Class *)myClass

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

精彩评论

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

关注公众号