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

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -