When inside an instance method, I can refer to the instance's class via [self class]
, so I don't have to write [MyClass class]
explicitly.
在实例方法中,我可以通过[self class]引用实例的类,因此不必显式地编写[MyClass]。
How would I achieve the equivalent inside a class method? There is obviously no self
defined in that context...
如何在类方法中实现等价的?很明显,在这种情况下没有自我定义……
2 个解决方案
#1
8
self
is defined inside a class method, but it refers to the class itself rather than to an instance of the class. So, in a class method, just use self
instead of [self class]
.
self是在类方法中定义的,但是它引用类本身而不是类的实例。因此,在类方法中,只使用self而不是[self class]。
#2
2
Actually there is a self a Class method. It will return the Class of highest inheritance.
实际上有一个self a类方法。它将返回最高继承的类。
#1
8
self
is defined inside a class method, but it refers to the class itself rather than to an instance of the class. So, in a class method, just use self
instead of [self class]
.
self是在类方法中定义的,但是它引用类本身而不是类的实例。因此,在类方法中,只使用self而不是[self class]。
#2
2
Actually there is a self a Class method. It will return the Class of highest inheritance.
实际上有一个self a类方法。它将返回最高继承的类。