Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Playground code for the article
import Foundation
protocol CustomProtocol {
associatedtype AssociatedType
func foo(argument: AssociatedType)
}
//let array = [CustomProtocol]() // Gives error: Protocol 'CustomProtocol' can only be used as a generic constraint because it has Self or associated type requirements
public struct AnyCustomProtocol<T>: CustomProtocol {
func bar() -> T {
fatalError("Needs implementation")
}
func foo(argument: T) {
}
}
let array = [AnyCustomProtocol<Any>]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.