0

I'm calling appController from viewController upon viewDidLoad

@implementation viewController
    - (void)viewDidLoad { [super viewDidLoad];
        NSLog(@"viewDidLoad");
        [appController initialize];
    }
@end

@implementation appController
    + (void)initialize {
        NSLog(@"initialize");
    }
@end

I expected initialize to be executed once. But, as seen in the console, it's executed twice.

log output

Is this a bug or am I missing something?

Aleksander Azizi
  • 9,829
  • 9
  • 59
  • 87
  • 1
    the `initialize` class method is called automatically when an object is created by instantiation of the class. You don't need to call it directly. When you call it directly in your case, you are essentially calling it for the second time (because it was already called once automatically). – Adam Jenkins Mar 24 '14 at 17:12

1 Answers1

4

+ (void)initialize is a method that is called by the Objective-C runtime the first time the class is referenced.

You should never call this yourself, and never call super.

If you're looking to do setup on your data controller override init.

Here's a similar answer

Community
  • 1
  • 1
SkylarSch
  • 389
  • 2
  • 9