Created
September 14, 2015 16:33
-
-
Save rnewman/5f3fc04cf62bff220bdd to your computer and use it in GitHub Desktop.
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
/* | |
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