I have a protocol that uses a related type, as such:
protocol Populatable { typealias T func populateWith(object: T) }
and classes that implement the protocol:
class DateRowType: Populatable { func populateWith(object: NSDate) { print(object.description) } } class StringRowType : Populatable { func populateWith(object: String) { print(object) } }
but when I try to execute or check compliance, for example:
let drt = DateRowType() let srt = StringRowType() let rowTypes = [drt, srt] let data = [NSDate(), "foo"] for (i, p: Populatable) in enumerate(rowTypes) { p.populateWith(data[i]) }
I get an error message:
The protocol "Populatable" can only be used as a general restriction, since it has its own or related requirements like
What is the correct way to check if an object complies with the Populatable protocol?
Note: all the code needed to verify this question is contained in the question, just copy the blocks of code to the playground.
source share