Reputation: 203
Right now I want to split my ViewController, containing public methods, into several files for easier management and navigation. I know that categories can do this, but it's largely used by importing the categories each and everytime you want to use them. The ViewController I'm working on is meant to be subclassed A LOT of times, so that's not really an option.
What I want to achieve is splitting those public methods into categories and combine all those categories into one file, importing them in the header file to ensure that subclasses do not need to import them again and again.
Is there a way to do this? I searched around, but all that I've found is:
Declare the categories in one same header, declare them in multiple implementation file
This is not what I'm looking for, because I heavily document my code inline to take advantage of XCode 5's ability to display inline documents. Navigating the class without using Ctrl+6 is already a nightmare labyrinth due to all the documentation. It will alleviate the problem with implementation file, but not what I'm looking for.
Declare the categories in split headers
All that I've found regarding this are for private uses in that class only (import the categories in the implementation file). I need to split the public methods as well and have them available for subclasses to see.
I thought about creating a class that imports all the categories, essentially hiding the actual class, but that locks me out from protected variables (and I need those).
Is there a... solution to this, or is this really that impossible with the current Objective C?
EDIT: I've heard that DocSets is the way Apple go to allow them to display documentation without documenting the code inline. If using DocSet allows me to clean up my header code (that is, move the documentation elsewhere) and still have the documentation available in Quick Help, I'd like to learn that
Upvotes: 0
Views: 120
Reputation: 203
I decided to just split the implementation file. Restructuring the class for multiple headers took longer and is harder than I expected. I think the scenario that I posted cannot be solved in the way that I wanted it to be.
Upvotes: 0
Reputation: 8012
Declare your categories in separate header files. Write another header file whose sole purpose is to #include each of the category headers that has public API. Use that single header file when writing subclasses. Write yet another header file that includes the single public file and any additional private category headers, for your internal use.
This is similar to what frameworks do with their classes. Foundation's classes are declared in separate files NSObject.h, NSArray.h, etc. Then Foundation/Foundation.h includes each of the headers for public classes.
Upvotes: 1
Reputation: 25907
In these circumstances, I would import the necessary categories on the .h of the parent class, this way the subclasses get the categories as well.
Upvotes: 1