In Swift, it's often annoying that you cannot have a variable of a generic protocol type. You need to have a generic type implementing that protocol because you cannot specify associated types when declaring a variable.
For example, Swift has a Collection protocol, which has an associated generic type Element.
Instead of declaring a variable with let foo: Collection<Int> = ... you need to have a generic variable C: Collection where C.Element == Int, which can be pretty annoying because your enclosing structures also need to be generic.
Yes I am aware of the AnyCollection<Element> type but that is just a workaround that is specific to the collection protocol and not a general solution and yes I am aware that the Swift compiler always wants to specialize generics at compile time but this is just annoying.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Swift, it's often annoying that you cannot have a variable of a generic protocol type. You need to have a generic type implementing that protocol because you cannot specify associated types when declaring a variable.
For example, Swift has a Collection protocol, which has an associated generic type Element.
Instead of declaring a variable with
let foo: Collection<Int> = ...
you need to have a generic variableC: Collection where C.Element == Int
, which can be pretty annoying because your enclosing structures also need to be generic.Example
It would be so much more pleasant to write
Yes I am aware of the
AnyCollection<Element>
type but that is just a workaround that is specific to the collection protocol and not a general solution and yes I am aware that the Swift compiler always wants to specialize generics at compile time but this is just annoying.