user491880
user491880

Reputation: 4869

iOS 5 Instance variables

I'm slightly confused as to how ARC works, I know there is automatic reference counting but does this functionality work even for assigning raw instance variables (not using the properties).

For instance, if I have an instance variable arr:

@interface TestClass : NSObject {
   NSArray *arr;
}

Now if inside a method I assign this using an auto-released NSArray:

- (IBAction)test {
    arr = [NSArray arrayWithObject:@"TEST"];
 }

What happens to this array? Does it just magically keep it until arr is reassigned to something else?

Now if I do something like:

self.arr = [NSArray arrayWithObject:@"TEST"];

What happens if it is strong vs. weak?

Upvotes: 14

Views: 4420

Answers (1)

Lily Ballard
Lily Ballard

Reputation: 185671

Yes, ARC works on raw ivar access. Just like local variables, ivars are implicitly __strong unless decorated with __weak or __unsafe_unretained. Therefore they will, by default, act like a property that's been marked strong (or retain, which under ARC is a synonym for strong).

Upvotes: 18

Related Questions