开发者

About the keyword of `self`

开发者 https://www.devze.com 2023-03-08 13:07 出处:网络
+ (void)Foo; - (void)Foo; In the method, - (void)Foo, the keyword self means an instance of th开发者_如何学Pythone class.
+ (void)Foo;
- (void)Foo;

In the method, - (void)Foo, the keyword self means an instance of th开发者_如何学Pythone class. But in the method, + (void)Foo, What does the keyword self mean? Does it mean the Class ?


self is one of the two implicit parameters to every method. It is a pointer to an object, and initially it is whatever object received the message to invoke the method that's executing. When the method in question is an instance method, self will be an instance of the class in which the method is defined, or one of its subclasses. In the case of a class method, self will be the class object.


Yes. The following works just fine:

+(id)myObjectWithInt:(NSInteger)anInt {
    return [[[self alloc] initWithInt:anInt] autorelease];
}
0

精彩评论

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

关注公众号