I'm looking at Apple's MVC Networking sample project and I have found that in the class PhotoGallery
the author has created instance and class versions of the method abandonGalleryCacheAtPath:
:
On line 139:
+ (void)abandonGalleryCacheAtPath:(NSString *)galleryCachePath
On line 457:
- (void)abandonGalleryCacheAtPath:(NSString *)galleryCachePath
All the instance version of the method seems to do is a bit of logging before calling the class method as follows:
[[QLog log] logWithFormat:@"gallery %zu abandon '%@'", (size_t) self.sequenceNumber, [galleryCachePath lastPathComponent]];
[[self class] abandonGalleryCacheAtPath:galleryCachePath];
The log message includes self.sequenceNumber
, which is an instance variable which would not be available to the class method.
A couple of questions:
- Will the system automatically direct calls to the right method e.g. if another class method calls
self abandonGalleryCacheAtPath:abc
then the class version of the method will be executed, and if another instance method calls it then the instance version of the method will be executed? - Do you think the author has implemented the instance method purely so that the value of
sequenceNumber
can be logged? Are there any other design/technical benefits of doing this kind of double implementation?