Search code examples
objective-cretain

retain C array in objective-c


i create a c array in the firstClass (this is created in the interface):

BOOL        taken[25];

i then go to a different view and come back to the first one, except my c array is reset to 0,

how do i retain my array when i go back an forth between views?


Solution

  • You cannot send retain messages to plain C arrays. Normal C memory management applies. I.e. local stack variables will fade away when out of scope, global variables will live, etc. Use dynamically allocated memory (malloc or new in C++) if you need "long-living" memory, but you are responsible to free it when you're done with it.