Is the weakSelf/strongSelf dance really necessary when referencing self inside a non-retained completion called from a UIViewController?

As I believe you correctly diagnosed, using self will not necessarily cause strong reference cycle in this scenario. But this will retain the view controller while the network operation completes, and in this case (as in most cases), there’s no need to. Thus, it may not be necessary to do use weakSelf, but probably prudent … Read more

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

Weak Reference to NSTimer Target To Prevent Retain Cycle

The proposed code: __weak id weakSelf = self; timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:weakSelf selector:@selector(tick) userInfo:nil repeats:YES]; has the effect that (i) a weak reference is made to self; (ii) that weak reference is read in order to provide a pointer to NSTimer. It won’t have the effect of creating an NSTimer with a weak reference. … Read more

Using weak self in dispatch_async function

Assuming, self is an object pointer to a UIViewController. Things to consider: A UIViewController is a “UIKit” object. UIKit objects shall not be sent methods on non-main threads, that is – those methods must execute on the main thread only! A block that has been enqueued in a queue – whether this was synchronously or … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)