Skip to content

Instantly share code, notes, and snippets.

@fewlinesofcode
Created November 9, 2018 17:11
Show Gist options
  • Save fewlinesofcode/d7bd1f0b6a4353f9f7279ceb3b1eda19 to your computer and use it in GitHub Desktop.
Save fewlinesofcode/d7bd1f0b6a4353f9f7279ceb3b1eda19 to your computer and use it in GitHub Desktop.
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