Objective-C ARC and Instance Variables iOS SDK
ios, objective-c
Solution
Are we supposed to convert all of the local variables we wish to retain to private properties or am I missing something obvious?
First, the variable you showed in your example is an instance variable, not a local variable. Local variables are declared inside a block of code (e.g. inside a function or method, or inside some sub-block such as the body of a conditional statement) and have a lifetime that's limited to the execution of the block in which they're declared. Instance variables are declared in a class; each instance of that class gets its own copy of the instance variables declared by the class.
Second, no, you don't need to convert all your instance variables to properties. Instance variables are treated as strong references by default under ARC. A property is really just a promise that a class provides certain accessors with certain semantics. Just having an instance variable doesn't mean that you have to provide accessors for that ivar. (Some might say that you should, but you don't have to.)
Problem
Are we supposed to convert all of our instance variables we wish to retain to private properties or am I missing something obvious? ``` @interface SomethingElse : Something { NSMutableArray *someArray; } ``` In this example, someArray is initialized in a method with [NSMutableArray initWithObject:someObject] but isn't retained. My particular situation is I'm updating a game, there are a lot of instance variables, so I want to make sure I'm doing this right for the sake of future versions of the sdk.