NSObject initialize () is not called in release build configuration

According to Apple's documentation, initialize() method Initializes a class before it receives its first message.

Can someone explain why initialize () does not work in release build configuration?

For instance:

 class Test: NSObject { override class func initialize() { print("initialize") } class func test() { print("test") } } class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() Test.test() } } 

Output in debug configuration:

 initialize test 

The output in the Release configuration:

 test 
+5
source share
1 answer

I did a quick test and it looks like in the configuration Release + initialize not called unless you create an instance of the class. However, in Debug calling the class method is enough to call +initialize . Looks like an undocumented warning.

Edit: An even more interesting fact is that for an Objective-C project in the Debug and Release configurations that invoke the class method, just call + initialize . I would say that this is a mistake. You might want to record a radar for him.

+3
source

Source: https://habr.com/ru/post/1260271/


All Articles