In the past, when I’ve had to compile something on Snow Leopard (or any older Mac OS X) and use some @selector that’s available on Lion and higher, I’ve done something like this:
if([foo respondsToSelector:@selector(awesomeLionSelector)]) {
[foo awesomeLionSelector]
}
And this has worked great. So, now I’m trying to do the same thing for a new method that returns a float, but the following line:
float f = [foo awesomeLionSelectorWhichReturnsFloat];
throws a compile error: “cannot convert ‘objc_object*’ to ‘float’ in assignment”. This is because the compiler doesn’t know about the method and has to assume a return type of ‘id’.
What is the proper way to fix this?
EDIT: according to John Caswell comment, the correct runtime function to use is
objc_msgSend_fpret(), which returns a double.I think you should try your way with: objc_msgSend_stret():
Something like: