i got errors because in section 'Adding Constraints to an Associated Type' i changed conditions from
associatedtype Item
to
associatedtype Item: Equatable
. And then if you use the code from other sections described above, it will cause errors.
The 'Adding Constraints to an Associated Type' section says:
You can add type constraints to an associated type in a protocol to require that conforming types satisfy those constraints.
the official documentation does not say which code we should use next, from section 'Associated Types in Action' with his code:
1.protocol Container {
2. associatedtype Item
3. mutating func append(_ item: Item)
4. var count: Int { get }
5. subscript(i: Int) -> Item { get }
6. }
Or we should use, this code, from section 'Adding Constraints to an Associated Type':
- protocol Container {
- associatedtype Item: Equatable
- mutating func append(_ item: Item)
- var count: Int { get }
- subscript(i: Int) -> Item { get }
- }
Perhaps for beginners this is not entirely obvious.
p.s. sorry for my English
The code i am using:
Code from section 'Associated Types in Action' to section 'Generic Where Clauses'