4 ms·
I wrote a report about how using Objective-C categories to implement UIViewController feature modules can be really elegant. [1] The same would be true, I imagi
by srcreigh 12y ago
I wrote a report about how using Objective-C categories to implement UIViewController feature modules can be really elegant. [1] The same would be true, I imagine, for what would be Swift's multiple inheritance. The following is a quick summary of this report, with thoughts about multiple inheritance.
You may find yourself having a set of UIViewControllers that implement overlapping subsets of the features that your app provides (i.e. one controller has features A and B, another has features B and C, a third has features C and A).
One method of solving this is to create helper modules that implement the features A, B, and C. In your controllers, you can then set up the appropriate subset of helper modules. There are a few problems with this: 1) there's still boilerplate code; 2) the implementation can be subtle (make sure to retain the reference to all your helper classes!).
This can be elegantly solved with Objective-C categories (by creating a category for each feature) or, I imagine, what multiple inheritance would look like in Swift. Instead of boilerplate helper module initialization and subtle implementation, your ABUIViewController could inherit from abstract AUIViewController and BUIViewController base classes to get both features for free in virtual methods.
[1]: http://srcreigh.github.io/blog/posts/modular-uiviewcontroller-features/ http://srcreigh.github.io/blog/posts/modular-uiviewcontrolle...