According to Apple documentation initialize()
method Initializes the class before it receives its first message.
Can somebody explain why initialize() is not working in Release build configuration?
For example:
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
Output in Release configuration:
test
I did a quick test and it looks like in Release
configuration + initialize
is not called unless you create an instance of the class. However in Debug
calling a class method is enough to trigger +initialize
. Looks like an undocumented caveat.
Edit:
Even more interesting fact is that for Objective-C project in both Debug
and Release
configurations calling a class method is enough to trigger + initialize
. I would say this is a bug. You might want to file a radar for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With