I have a class
class Service: NSObject {
let wirlessSerivce: WirlessSerivce
override init()
{
super.init()
wirlessSerivce = WirlessSerivce()
wirlessSerivce.delegate.addDelegate(self)
}
}
I got these two issues:
Property 'self.wirlessSerivce' not initialized at super.init call
Immutable value 'self.wirlessSerivce' may only be initialized once (change let to var)
The goal I want to achieve is create wirlessSerivce
and subscribe Service
class to wirlessSerivce
updates via delegate. I use multicast delegate and want to notify my Service
if some data changes in wirlessSerivce
Also can I do something like this:
class Service: NSObject {
let wirlessSerivce = WirlessSerivce() {
didSet {
wirlessSerivce.delegate.addDelegate(self)
}
}
As I understood let wirlessSerivce = WirlessSerivce() will create an instance even before class gets its initialize method. Right?
Seems this code works:
class Service: NSObject {
var wirlessSerivce: WirlessSerivce!
override init()
{
super.init()
wirlessSerivce = WirlessSerivce()
wirlessSerivce.delegate.addDelegate(self)
}
}
but here are few issues: var is for mutable properties and I don't need mutable service actually. (!)
says that instance will be initialized before use it from anywhere. But I initialize it in init
func, do I really need to mark it with (!)