views:

48

answers:

1

I'm using class_getProperty() in my iPad app(I imported objc/objc-runtime.h). And it works successfully on iPad simulator. But when I tried to run it on my iPad, Xcode said "objc/objc-runtime.h: No such file or directory" and "warning: implicit declaration of function 'class_getProperty'". So it didn't works.

Please help me.

+2  A: 

Please note that there are differences between the simulator and the device. The simulator does not run the exact same SDK as the device. The lower layers are from the Mac SDK actually, which makes sense since it's executed on a mac.

However, it seems there is a fix for your specific problem. You should definitely try the fix Jeff Lamarche describes in this post: Device vs. Simulator

Replace

#import <objc/objc-runtime.h>

By

#import <objc/runtime.h>
#import <objc/message.h>

Then to get rid of the warning, you add these two lines in the header file of the involved class :

#if (TARGET_OS_IPHONE)
- (NSString *)className;
+ (NSString *)className;
#endif

And then in the implementation file :

#if (TARGET_OS_IPHONE)
- (NSString *)className {
 return [NSString stringWithUTF8String:class_getName([self class])];
}
+ (NSString *)className {
 return [NSString stringWithUTF8String:class_getName(self)];
}
#endif
Luzal
I appreciate you for very quick answer!And it successfully worked!I'll be careful for differences between the simulator and the device from now.
tr0cd
Great ! If the answer suits, maybe you can mark it as accepted so other people who encounter this issue may instantly see this fix is correct ?
Luzal