In your code
void * someFunction() {
... code to create invocation and other things
CGRect aRect;
[invocation getReturnValue:&aRect];
finalValue = &aRect;
return finalValue
}
You're returning an address of a temporary object and invoking undefined behavior. aRect
is invalid as soon as someFunction
returns.
When you access it the memory address in CGRect returnedRect = *(CGRect *)returnValue;
you're using memory that doesn't belong to you hence why you're seeing weird numbers.
If you want to return the CGRect, you could just return the object directly. For example
CGRect someFunction() {
... code to create invocation and other things
CGRect aRect;
[invocation getReturnValue:&aRect];
return aRect;
}
and use it like
CGRect returnedRect = someFunction(arguments);