0

我有一个实现一些类方法的基类。它使用类名来推断它是什么资源并远程获取它。

@implementation BaseResource : CPObject

+ (id)find:(CPString)identifier
{
}

我希望能够从像这样的实例方法调用类方法

- (id)initWithCoder:(CPCoder)aCoder
{
    [self find:1]; // This does not work
    [BaseResource find:1];  // This works but will not resolve to the right resource name
}

我不想使用 BaseResource 类名,因为它需要为具有不同名称的子类工作。

如何在不显式使用类名的情况下从实例方法调用类方法?

4

1 回答 1

2
[self class] 

会成功的。

例如

[[self class] find:1] 
于 2012-02-27T18:43:46.767 回答