Re: [swift-users] Conforming to the protocol requirements with implicitly unwrapped optional

2017-05-29 Thread Zhao Xin via swift-users
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)

Re: [swift-users] Conforming to the protocol requirements with implicitly unwrapped optional

2017-05-29 Thread Anton Bronnikov via swift-users
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

Re: [swift-users] Conforming to the protocol requirements with implicitly unwrapped optional

2017-05-28 Thread Zhao Xin via swift-users
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

[swift-users] Conforming to the protocol requirements with implicitly unwrapped optional

2017-05-28 Thread Anton Bronnikov via swift-users
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