I know how to create singleton class in swift. The best and easy way to create singleton class is the following:
class Singleton {
static let sharedInstance = Singleton()
}
But I don't need singleton for any normal class. I need to create singleton for a viewcontroller class. So I'm using this code create singleton
class AViewController:UIViewController {
static let sharedInstance = AViewController()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
it gives me error near AViewController()
Missing argument for parameter 'coder' in call
Looks like it want me to initialize with init(coder: NSCoder)
. But what parameter or value should I pass through the coder
?
class Singleton : NSObject
this? – Claretrequired init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) }
– Barnabyinit
methods? At least show the method signatures. – Sudanicinit
method. Please see the updated question. – Cambricrequired init
method, then why are you asking what parameter or value should I pass through the coder? – Barnabyinit? (coder aDecoder: NSCoder)
and this want me to pass a coder value. – Cambric