Skip to content

Instantly share code, notes, and snippets.

@guidomb
Created June 3, 2017 14:00
Show Gist options
  • Save guidomb/3b7bbc9ede3776e5e9662a313862ffbe to your computer and use it in GitHub Desktop.
Save guidomb/3b7bbc9ede3776e5e9662a313862ffbe to your computer and use it in GitHub Desktop.
Swift constrained extension where fixed type is generic
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