Referring to weak self inside a nested block

Your code will work fine: the weak reference will not cause a retain cycle as you explicitly instruct ARC not to increase the retainCount of your weak object. For best practice, however, you should create a strong reference of your object using the weak one. This won’t create a retain cycle either as the strong … Read more

Correct bridging for ARC?

As mentioned in the comments, I think it’s fine to talk about ARC and the contents of Automatic Reference Counting here. __autoreleasing is not meant to be used like that. It’s used for passing indirect object references (NSError**, etc). See 4.3.4 Passing to an out parameter by writeback. According to 3.2.4 Bridged casts, the __bridge_transfer … Read more

Is NSNotificationCenter removeObserver in ARC needed? [duplicate]

You should explicitly remove the observer even you use ARC. Create a dealloc method and remove there.. -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } If you see the method you don’t need to call [super dealloc]; here, only the method without super dealloc needed. UPDATE for Swift You can remove observer in deinit method if you … Read more

how to use delegates with Automatic Reference Counting

“ivar” means “instance variable”, which you have not shown. I’m betting it looks something like this: @interface Foo : NSObject { id delegate; } @property (weak) id delegate; What the error is saying is that it must look like this: @interface Foo : NSObject { __weak id delegate; } @property (weak) id delegate; If the … Read more

Instance variables declared in ObjC implementation file

This is indeed a new language feature, and if you must declare your ivars (rather than simply declaring properties and letting the compiler generate ivars for you) it’s a good practice. Your header files in theory should only expose public interface for your classes; everything else belongs in the implementation. One caveat is that implementation-file … Read more

Should I refer to self.property in the init method with ARC?

Use direct access in partially constructed states, regardless of ARC: – (id)initWithReminder:(Reminder*)reminder_ { self = [super init]; if (self) { reminder = reminder_; // OR reminder = [reminder_ retain]; } return self; } This is because self.whatever will trigger other side effects, such as Key-Value Observing (KVO) notifications, or maybe your class implements (explicitly) or … Read more