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?
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With