It's fairly simple to find all the superclasses (I presume this is what you meant, rather than subclasses); you simply loop until class.superclass == NSObject.class.
Do note @bbum's comments about this being a bad code smell though. Read his answer and consider alternative approaches, and really think about why you want to do this and if there's a better way.
That said, here's a full code example that retrieves all the BOOL properties from a class. It would be easy to extend it for other property types - see the linked questions.
/**
* Get a name for an Objective C property
*
*/
- (NSString *)propertyTypeStringOfProperty:(objc_property_t) property {
NSString *attributes = @(property_getAttributes(property));
if ([attributes characterAtIndex:0] != 'T')
return nil;
switch ([attributes characterAtIndex:1])
{
case 'B':
return @"BOOL";
}
assert(!"Unimplemented attribute type");
return nil;
}
/**
* Get a name->type mapping for an Objective C class
*
* Loosely based on http://stackoverflow.com/questions/754824/get-an-object-properties-list-in-objective-c
*
* See 'Objective-C Runtime Programming Guide', 'Declared Properties' and
* 'Type Encodings':
* https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101
* https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100-SW1
*
* @returns (NSString) Dictionary of property name --> type
*/
- (NSDictionary *)propertyTypeDictionaryOfClass:(Class)klass {
NSMutableDictionary *propertyMap = [NSMutableDictionary dictionary];
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList(klass, &outCount);
for(i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
const char *propName = property_getName(property);
if(propName)
{
propertyMap[@(propName)] = [self propertyTypeStringOfProperty:property];
}
}
free(properties);
return propertyMap;
}
- (NSDictionary *)settingsProperties
{
if (!_settingsProperties)
{
Class class = _settings.class;
NSMutableDictionary *propertyMap = [[NSMutableDictionary alloc] init];
do
{
[propertyMap addEntriesFromDictionary:[self propertyTypeDictionaryOfClass:class]];
}
while ((class = class.superclass) != NSObject.class);
_settingsProperties = propertyMap;
}
return _settingsProperties;
}