I have a bit of code that calls a method on an object whose .h file I don't have contained in my project, and cannot have contained (I don't want to get into this).
However, I know that I need to call a specific function that it does have, which returns an NSTimeInterval
.
Obviously, the compiler warns me that the method is not defined and might crash. The problem is that the compiler defaults the return value of unknown functions to id, and i cannot cast an id to an non-pointer value. At runtime, however, the value of id
is the value I need the NSTimeInterval
to contain.
id tempValue = [myObject unknownNumberMethod]; // compiler says: "instance method -unknownNumberMethod not found(return type defaults to 'id'
NSTimeInterval realValue = (NSTimeInterval)tempValue; //this yields a compilation error:/Users/Niv/Projects/Copia/Copia.MAC/RMSDKServicer/RMSDKServicer/Downloader/ActivatorService.m:75:24: Initializing 'NSTimeInterval' (aka 'double') with an expression of incompatible type 'id'
I tried declaring the method like this, just to make the compiler understand it returns an NSTimeInterval
and not an id
:
@interface MyClass //type of myObject
-(NSTimeInterval)unknownNumberMethod;
@end
however, this makes the unknownNumberMethod
return 0
constantly, so I assume it overwrites the real method with a blank one.
I also looked for some way to define an extern
method of a class, but couldn't find the right syntax.
what is the correct way to "force" the compiler into realising that even though it doesn't find the method definition, it returns an NSTimeInterval
and not an id
?