Created
June 3, 2017 14:00
-
-
Save guidomb/3b7bbc9ede3776e5e9662a313862ffbe to your computer and use it in GitHub Desktop.
Swift constrained extension where fixed type is generic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol Route: Equatable { | |
var previous: Self? { get } | |
} | |
internal enum InternalAction<RouteType: Route, MessageType> { | |
case navigateToPreviousRouteAfterPop | |
case action(Action<RouteType, MessageType>) | |
} | |
public final class Mailbox<MessageType> { | |
fileprivate var subscribers: [(MessageType) -> ()] = [] | |
public func subscribe(subscriber: @escaping (MessageType) -> ()) { | |
subscribers.append(subscriber) | |
} | |
} | |
// This does not compile because Any: Route is not valid syntax. | |
extension Mailbox where MessageType == InternalAction<Any: Route, Any> { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment