Questions tagged [protocol-inheritance]
4 questions
8
votes
1 answer
How to make protocol associated type require protocol inheritance and not protocol adoption
In my swift project I have a case where I use protocol inheritance as follow
protocol A : class{
}
protocol B : A{
}
What Im trying to achieve next is declaring another protocol with associated type, a type which must inherit from protocol A.…

Zell B.
- 10,266
- 3
- 40
- 49
5
votes
2 answers
Protocol inheritance issue
I try to set up various protocols that work hand in hand. Unfortunately I cannot make them work the way I want. Looking at the following code, I think my goal is obvious: I want to require a class that conforms to a protocol X. If it conforms to…

alexeis
- 2,152
- 4
- 23
- 30
2
votes
1 answer
How to pass a sub protocol type where a super protocol type is expected in Swift? (Think passing subclass type for baseclass type but for protocols)
I am stuck on a protocol inheritance problem in Swift. I am trying to construct an API that accepts an array of Protocol Types X. Consumers of this API should be able to then pass in any type of protocol type X OR any sub protocol type X' that…

AyBayBay
- 1,726
- 4
- 18
- 37
1
vote
1 answer
Computed property to sum numeric arrays in Swift
Task from book says: without calling reduce(_: _:) method, sum sequences of numbers by adding a computed property called sum. You should be able to use it like this:
[3, 7, 7].sum // 17
[8.5, 1.1, 0.1].sum // 9.7
Hint by authors: in…

mairo
- 155
- 8