Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 251
user491880 Avatar asked Oct 14 '11 23:10

user491880


1 Answers

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).

like image 160
Lily Ballard Avatar answered Sep 19 '22 16:09

Lily Ballard