Why does Apple recommend to use dispatch_once for implementing the singleton pattern under ARC?

dispatch_once() is absolutely synchronous. Not all GCD methods do things asynchronously (case in point, dispatch_sync() is synchronous). The use of dispatch_once() replaces the following idiom: + (MyClass *)sharedInstance { static MyClass *sharedInstance = nil; @synchronized(self) { if (sharedInstance == nil) { sharedInstance = [[MyClass alloc] init]; } } return sharedInstance; } The benefit of dispatch_once() … Read more

Objective-C ARC: strong vs retain and weak vs assign

After reading so many articles Stackoverflow posts and demo applications to check variable property attributes, I decided to put all the attributes information together: atomic //default nonatomic strong=retain //default weak retain assign //default unsafe_unretained copy readonly readwrite //default Below is the detailed article link where you can find above mentioned all attributes, that will definitely … Read more

Should IBOutlets be strong or weak under ARC?

WARNING, OUTDATED ANSWER: this answer is not up to date as per WWDC 2015, for the correct answer refer to the accepted answer (Daniel Hall) above. This answer will stay for record. Summarized from the developer library: From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should … Read more

performSelector may cause a leak because its selector is unknown

Solution The compiler is warning about this for a reason. It’s very rare that this warning should simply be ignored, and it’s easy to work around. Here’s how: if (!_controller) { return; } SEL selector = NSSelectorFromString(@”someMethod”); IMP imp = [_controller methodForSelector:selector]; void (*func)(id, SEL) = (void *)imp; func(_controller, selector); Or more tersely (though hard … Read more

How can I disable ARC for a single file in a project?

It is possible to disable ARC for individual files by adding the -fno-objc-arc compiler flag for those files. You add compiler flags in Targets -> Build Phases -> Compile Sources. You have to double click on the right column of the row under Compiler Flags. You can also add it to multiple files by holding … Read more

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