Post

Replies

Boosts

Views

Activity

Some Animal and local scope of underlying type
Trying to understand why my Xcode-beta 2 is not able to understand the underlying type for the following example /// Protocol that has the idea of draw protocol Drawable {     func draw() } /// Implementation of a circle which is drawable struct Circle: Drawable {     func draw() {         print("Circle")     } } /// Implementation of a Triangle which is drawable struct Triangle: Drawable {     func draw() {         print("Triangle")     } } /// Let make an instance as shown in the example in the `Embrace Swift Generics` Talk func underlyingTypeDoesNotChangeWithinTheScop() {     var drawable: some Drawable = Circle()     drawable.draw()     drawable = Circle() /// 👈🏽 This line should compile, since the underlying type does not change within the scope     drawable.draw() } Why am I getting the following error cannot assign value of type 'Circle' to type 'some Drawable' when I try to assign Circle to var drawable, from what I understand the underlying type remains the same within the scope. Is this an Xcode14-beta 2 issue?
4
0
772
Jul ’22