I'm writing a singleton class to access socket by adopting socket.IO-objc, here's what I did so far:
class Singleton_SocketManager: NSObject, SocketIODelegate {
var isSocketConnected: Bool = false
var socket: SocketIO
override init() {
super.init()
}
class var sharedInstance: Singleton_SocketManager {
struct Static {
static var onceToken: dispatch_once_t = 0
static var instance: Singleton_SocketManager? = nil
}
dispatch_once(&Static.onceToken) {
Static.instance = Singleton_SocketManager()
}
return Static.instance!
}
}
Yet the compiler complains:
Property 'self.socket' not initialized at super.init call
How should I write my init method here to make the compilation error go away?
By the way, I transitioned the code above from objective-c, in obj-c, the SocketIO is initialized like so:
self.socket = [[SocketIO alloc] initWithDelegate:self];
And If I put the init method this way:
override init() {
self.socket = SocketIO(delegate: self)
super.init()
}
It complains:
self used before super.init call