I have a weird EXC_BAD_ACCESS crash, I'm trying to initialise an object by using singleton like this :
@objc final class Toto: XSuperClass {
/// Singleton
@objc static var instance = Toto()
/// Hide the creator to force using singleton
@objc private init() {
print("Initializer is called !")
super.init(
"xyz",
serverHost: "",
serverPath: ""
)
}
@objc func update() {
...
}
The XSuperClass extends from NSObject and contained in a pod.
In Appdelegate :
-(void)applicationDidBecomeActive:(UIApplication *)application
{
[[Toto instance] update];
}
Sometimes it crashes at : @objc static var instance = Toto() Thread 1: EXC_BAD_ACCESS (code=1, address=0x9)
The thread 1 contains :
#11 0x0000000105a20004 in Toto.instance.unsafeMutableAddressor at /Users/.../Toto.swift
#10 0x00000001076196d9 in swift_once ()
#8 0x0000000107e5ad48 in _dispatch_client_callout ()
#7 0x0000000105a1ff90 in globalinit_33_0DC663E05309E94BD36536F7E931D58A_func0 at /Users/../Toto.swift
#6 0x0000000105a21028 in type metadata accessor for Toto ()
#0 0x0000000107602737 in swift_checkMetadataState ()
The XSuperClass :
/** This class is the base class that handles ... */
@objc open class XSuperClass: NSObject {
...
/// Main initializer
public init(_ feature: String,
... dependencies that all have default values,
serverHost: String?,
serverPath: String?
) {
self.feature = feature
...
self.serverHost = serverHost
self.serverPath = serverPath
}
It seems that I'm trying to initialise a released object in memory, but I can't figure out how to fix this, I spent a lot of time investigating the problem with no luck, any ideas please ?