Last active
August 29, 2015 14:12
-
-
Save NachoSoto/1f0e7ed17ec6cd50607c to your computer and use it in GitHub Desktop.
Generic parameter ’T’ cannot be bound to non-@objc protocol type ‘Protocol’.
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
protocol BaseProtocol {} | |
protocol ExtendedProtocol: BaseProtocol {} | |
class A<T: BaseProtocol> { | |
private let t: T | |
init(a: T) { self.t = a } | |
} | |
class B<T: ExtendedProtocol> { | |
private let a: A<T> | |
init(a: A<T>) { self.a = a } | |
} | |
class ExtendedClass: ExtendedProtocol {} | |
// This isn't possible either :( | |
let a: A<ExtendedProtocol> = A(a: ExtendedClass()) | |
let b: B<ExtendedProtocol> = B(a: a) |
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
protocol Protocol {} | |
class A<T: Protocol> { | |
private let array: [T] | |
init(a: [T]) { self.array = a } | |
} | |
class Class1: Protocol {} | |
class Class2: Protocol {} | |
let array: [Protocol] = [ | |
Class1(), | |
Class2() | |
] | |
// Generic parameter ’T’ cannot be bound to non-@objc protocol type ‘Protocol’. | |
let a: A<Protocol> = A(a: array) | |
// Unfortunately `T` can only be a class type, not a protocol. | |
// But `Class1` and `Class2` are only related by a protocol. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment