I have a class hierarchy as follows
@interface PTLDatasource : NSObject
...
@interface PTLFetchedDatasource : PTLDatasource
...
And I want to add platform specific extensions to these classes that are defined in a protocol and implemented in a category:
@protocol PTLTableViewDatasource
- (void)foo;
...
@interface PTLDatasource (TableViewExtensions) <PTLTableViewDatasource>
...
@interface PTLFetchedDatasource (TableViewExtensions) <PTLTableViewDatasource>
...
A basic implementation of -foo:
is done in the PTLDatasource category. However, I also need a custom implementation of -foo:
in PTLFetchedDatasource which may then fallback to the PTLDatasource implementation.
Currently I'm trying to swizzle the implementations in PTLFetchedDatasource (TableViewExtensions)
in +load
, but I'm running into issues where +load
in PTLFetchedDatasource (TableViewExtensions)
is called before +load
in PTLDatasource (TableViewExtensions)
, so swizzling fails because the PTLDatasource implementation of -foo:
doesn't exist yet.
Is there a way to work around this load timing issue?
Do I even need swizzling? I know that overriding class member methods in a category is a no-no, but could I just call [super foo:]
from the PTLFetchedDatasource (TableViewExtensions)
implementation?
Thanks.
Mike Ash confirmed for me that swizzling is unnecessary and I can just call through to super. The only concern with overriding the category method would be if it was done multiple times on the same class.