Skip to content

Instantly share code, notes, and snippets.

@leviathan
Last active August 29, 2015 14:05
Show Gist options
  • Save leviathan/72f3f94893cf62893507 to your computer and use it in GitHub Desktop.
Save leviathan/72f3f94893cf62893507 to your computer and use it in GitHub Desktop.
Object discovery
#import <objc/runtime.h>
- (NSArray *)discoverAppModuleClasses
{
NSMutableArray *appModuleClasses = [NSMutableArray array];
// Integrate all classes which comply to the provider protocol
unsigned int count = 0;
Class *classList = objc_copyClassList(&count);
for (NSUInteger index = 0; index < count; index++)
{
Class classReference = classList[index];
if (class_conformsToProtocol(classReference, @protocol(SomeDefinedProtocolDefinition)))
{
[appModuleClasses addObject:classReference];
}
}
return appModuleClasses;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment