31

I'm trying to get the properties from my class using obj-c runtime approach I found on the answers from here, however I'm getting a lot of warnings/error when coding, do I need to import the library or make something in order to have the obj-c runtime functions available?

objc_property_t *properties = class_copyPropertyList([self class], &outCount);

Warning: "Implicit declaration of function 'class_copyPropertyList' is invalid in C99 Error: Use of undeclared identifier 'objc_property_t'

This is the whole chunk that I've copied:

unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList([self class], &outCount);
for (i = 0; i < outCount; i++) {
    objc_property_t property = properties[i];
    NSString *propertyName = [[NSString alloc] initWithCString:property_getName(property)];
    id propertyValue = [self valueForKey:(NSString *)propertyName];
    if (propertyValue) [props setObject:propertyValue forKey:propertyName];
}
free(properties);

Thanks in advance!.

David Ravetti
  • 2,030
  • 1
  • 17
  • 22
Rubs
  • 809
  • 9
  • 21
  • The error message means that you're using functions and types that aren't understood by the compiler. Find out how to fix that, and go from there... – Chris Devereux Jul 12 '12 at 17:11

1 Answers1

92

You have to import the runtime

#import <objc/runtime.h>
jerrylroberts
  • 3,419
  • 23
  • 22