0

I was trying to get the property name with following codes and hit the linker error, Undefined symbols: "_getPropertyType"

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];
    const char *propName = property_getName(property);
    if(propName) {
        const char *propType = getPropertyType(property);
        NSString *propertyName = [NSString stringWithUTF8String:propName];
        NSString *propertyType = [NSString stringWithUTF8String:propType];
        }
    }
 }

I already import #import "objc/runtime.h", so is there any linker flag I need to turn on ?

Thanks!

Qiulang
  • 10,295
  • 11
  • 80
  • 129
  • 1
    Are you calling getPropertyType()? What else do you do in that code? –  Apr 23 '11 at 02:02
  • Yes I am calling getPropertyType(). I have pasted all the codes related to runtime reference again. It is quite simple, right? I guess I must miss something (maybe even stupid :$) – Qiulang Apr 23 '11 at 03:05

2 Answers2

1

As the linker told you, there’s no getPropertyType() function exported by the Objective-C runtime API. In fact, the compiler should’ve warned you before the linker since there’s no corresponding declaration.

The runtime API does export a function called property_getAttributes that returns a C string describing the property type. This is described in the Objective-C Runtime Programming Guide document. You need to parse that string in order to obtain whichever information you want.

There’s another question on Stack Overflow in which one answer contains the definition of a getPropertyType() function that parses the string returned by property_getAttributes(). It might be what you’re looking for. In fact, your code looks quite similar to the code in the other answer.

Community
  • 1
  • 1
  • Yes indeed like you said, compiler did not give me any warning so I was confused what was going on here and did not realize that just means there’s no getPropertyType() function exported by the Objective-C runtime API. Thanks! And thanks for the link, I did copy my codes from somewhere (not from that link though) – Qiulang Apr 23 '11 at 15:44
  • @Qiulang Just curious: any particular reason why you’ve chosen Jonathan’s answer over mine? –  Apr 23 '11 at 23:42
  • No I did not choose his answer over yours. I did not even realize I chose his answer over yours. Of course your answer was more complete and I chose your (by checked it). Then I found both of you answered it again (or whatever that meant because your names both showed up at the second answer) so I checked it again. – Qiulang Apr 24 '11 at 09:44
  • Now since I learned I can only check one, I chose your answer of course. – Qiulang Apr 24 '11 at 09:46
  • @Qiulang Aha!, I thought that might have been the case. My name appears in his answer because I’ve edited it (corrected ABI to API). Cheers! –  Apr 24 '11 at 09:46
  • So you can edit others' answer ? That is weird,I did not realize in stackoverflow you can do that. Thanks for answering my question again. – Qiulang Apr 24 '11 at 09:51
  • @Qiulang Yes, Stack Overflow is collaboratively edited as explained in [the FAQ, question ‘Other people can edit my stuff?!’](http://stackoverflow.com/faq). Depending on the reputation, edits can be automatically applied or stay in a pending state awaiting for other people to approve them. –  Apr 24 '11 at 09:55
0

getPropertyType() isn't part of the Objective-C API. (i.e. the function doesn't exist in libobjc.)

Jonathan Grynspan
  • 43,286
  • 8
  • 74
  • 104