I am reading some Objective-C code in a well-maintained GitHub repo. https://github.com/soffes/sskeychain/blob/master/SSKeychain.m
I came across some weird lines (at least weird to my eyes).
+ (NSArray *)allAccounts {
return [self accountsForService:nil error:nil];
}
I was taught that self refers to the instance itself in an instance method. So what does self mean here, in a class method?
Inside class methods,
selfrefers to the object representing the correspondingClass:This is the same object that you get in an instance method when you call
[self class].It is useful if you would like to call methods on the
classpolymorphically. For example, you can call[[self alloc] init]to create a new instance of the class on which the call is performed.