You can try this.
protocol Container : class {
var component: Component { get }
}
class ConcreteContainer : Container {
lazy var component: Component = { return Component(container: self) }()
}
class Component {
unowned let container: Container
init(container: Container)
Like I mentioned, it is necessary to use optional, but it can not be nil.
Consider the following example where I have to use an optional in order to
break retention cycle:
protocol Container : class {
var component: Component { get }
}
class ConcreteContainer : Container {
var componen
Why you have to use `unwrapped optional` at the first place? If you have to
use it, it means it could be nil. So it won't conform the protocol, which
requires the `value` never nil.
Zhaoxin
On Mon, May 29, 2017 at 12:37 PM, Anton Bronnikov via swift-users <
swift-users@swift.org> wrote:
> Hi All
Hi All,
If I have a protocol with a property requirement such as:
protocol Foo {
var value: Int { get }
}
.. and I need to conform to it using an implicitly unwrapped optional like:
struct Bar : Foo {
let value: Int! = nil
}
.. then the compiler fails with an error:
Playground executi