My problem is that I need to get this specific variable to be initialized no matter what, because there's another object that depends on this variable's value
Here's the code (I set the variable as global)
lazy var getToken = {
if let token = keychain["token"].string {
return token
}
}()
I'm using lazy because I need this to get initialized no matter what.
I got this error error When I trying to put it on a global file
'lazy' may not be used on an already-lazy global
Here's the object that is depending on this token
Singleton Design
class SocketIOManager: NSObject {
static let sharedInstance = SocketIOManager()
let socket: SocketIOClient!
private override init() {
super.init()
socket = SocketIOClient(socketURL: URL(string: mainURL)!, .connectParams(["token": getToken])])
}
}
If you take a look at socket =
at "token"
, that's where I need the token