KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In Objective-C is there a way to ask a Class if there are any Subclass implementations. I have a Base class which has multiple subclasses. I would like to loop through all the subclasses and perform a class selector on each of them. Edit : I have a set of classes that can process certain types of data. Each of the processors subclass a base class that provides methods that each processor needs. Each class knows what data it can process and some classes can process certain types of data better than others. I would like to have a class method on each class that would provide a response back to a factory class that says yes i can process that data, and give a indication of how well it can process it. The factory would then make the decision on which class to instantiate based on which class says it can process the data the best. I have also found this question from 2009 (I did search before I posted this but didn't find anything) Discover subclasses of a given class in Obj-C . Edit 2 : The + (void)load method looks to be the perfect solution to what I am looking for. So I now have the following: + (void)registerSubclass:(Class)subclass { NSLog(@"Registered %@", subclass); } In my base class the this is my subs. +(void)load { [BaseSwitch registerSubclass:[self class]]; } This now displays a debug message for each of the subclasses. My next question is (probably a stupid one), how do I store the classes that get registered in the registerSubclass method. Is there a way to have class variable that I can read later? Edit 3 : Found some example code here <a href="http://cocoawithlove.com/2009/07/simple-extensible-http-server-in-cocoa.html" r
Tags (comma-separated)
Save Edits
Cancel