Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I call super in +initialize?

Do I need to do this:

+(void)initialize{
     ...my stuff...
  [super initialize];
 }

That is to say, if I am over-riding initialize from the parent class (NSObject) in my App Delegate, to I need to make sure the super implementation also gets called? Or does that not apply since this is not an instance method?

Just how "safe" is this method? I'm implementing the iNotify library and the documentation suggests adding the setup to this method, but I've not previously used it for anything in the app, and want to know also if it can potentially conflict with something else unexpectedly?

like image 960
johnbakers Avatar asked Jul 19 '12 07:07

johnbakers


Video Answer


1 Answers

if you have subclasses of this class you better call your code using dispatch_once statement because each sublcass will call this method again

+(void)initialize
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^
    {
        //Your Code
    });
}

See this blog post by Mike Ash for details.

like image 96
Denis Mikhaylov Avatar answered Oct 02 '22 07:10

Denis Mikhaylov