ios - Allocate NSInteger* -


I'm sure there is nothing clear to me, but I want to make an example of an NSInteger pointer in Objective-C. - (NSInteger *) getIntegerPointer {NSInteger refValue = 0; NSInteger * theReturn = & amp; RefValue; Return; }

When I call this function the return is zero, but is valid with the debugger within the function.

Any suggestions? I do not want to convert theReturn to NSInteger.

variable refValue is a local variable, which means that it is on the stack While the -getIntegerPointer method is being executed. As the method goes back, the variable will run (the stack will be closed), so this address is no longer worthwhile.

If you want to return a valid indicator, you will have to allocate memory to the point being talked about, like this:

  - (NSITFor *) getIntegerPointer {NSInteger refValue = 0; NSInteger * theReturn = malloc (size (NSInteger)); * TheReturn = refValue; Return; }    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -