Skip to content

Instantly share code, notes, and snippets.

@rnewman
Created September 14, 2015 16:33
Show Gist options
  • Save rnewman/5f3fc04cf62bff220bdd to your computer and use it in GitHub Desktop.
Save rnewman/5f3fc04cf62bff220bdd to your computer and use it in GitHub Desktop.
/*
I'm trying to define a method in a protocol that's generic,
then implement it in a class and allow the class to also have
a member that refers to that type.
*/
class AAA {
let a: String
init(a: String) {
self.a = a
}
}
protocol Foo {
func foo<T: AAA>(things: [T])
}
class Bar<T: AAA>: Foo {
var collected: [T] = []
func foo<T: AAA>(things: [T]) {
// If we make this class generic, we can't make the types match.
collected.appendContentsOf(things) // Cannot invoke… with an argument list of type '([T])'.
}
}
var x: Foo! // Can't make the protocol generic, else we can't use it here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment