Avatar
omochimetaru 12/6/2017 9:45 AM
これはコンパイルできる protocol EventSinkProtocol { associatedtype Event func send(event: Event) } extension EventSinkProtocol { func asEventSink() -> EventSink<Event> { return EventSink.init() } } class EventSink<Event> : EventSinkProtocol { func send(event: Event) {} }
9:45 AM
これがコンパイルできない protocol EventSinkConvertible { associatedtype Event func asEventSink() -> EventSink<Event> } protocol EventSinkProtocol : EventSinkConvertible { func send(event: Event) } extension EventSinkProtocol { func asEventSink() -> EventSink<Event> { return EventSink.init() } } class EventSink<Event> : EventSinkProtocol { func send(event: Event) {} }
9:46 AM
これはコンパイルできる protocol EventSinkConvertible { associatedtype _Event func asEventSink() -> EventSink<_Event> } protocol EventSinkProtocol : EventSinkConvertible { associatedtype Event = _Event func send(event: Event) } extension EventSinkProtocol { func asEventSink() -> EventSink<Event> { return EventSink.init() } } class EventSink<Event> : EventSinkProtocol { func send(event: Event) {} }
9:47 AM
これもコンパイルできる protocol EventSinkConvertible { associatedtype Event func asEventSink() -> EventSink<Event> } protocol EventSinkProtocol : EventSinkConvertible { func send(event: Event) } extension EventSinkProtocol { func asEventSink() -> EventSink<Event> { return EventSink.init() } } class EventSink<E> : EventSinkProtocol { typealias Event = E func send(event: E) {} }