I’ve been reading swift documentation and apparently protocols force structures, classes or enumerations to implement specific methods or define certain variables.
I’ve double checked this functionality by typing the following code. In fact, xcode compiler helped me to verify this since it popped up an alert that depicted the following message : “Type MiguelStruc does not conform to protocol Miguels …”
protocol Miguels {
func someF()-> Float
}
public struct MiguelStruc{
var miguelVar : String = "hey"
}
extension MiguelStruc: Miguels{
}
Now, while I was following the official swiftUI drawing paths and shapes tutorial I encountered this particular chain of code: (https://developer.apple.com/tutorials/swiftui/drawing-paths-and-shapes)
Path { path in
}
.fill(.black)
By pressing command + click on the Path {…} instance, I could explore the Swiftui documentation and, indeed, I noticed that Shape is a protocol
public protocol Shape : Sendable, Animatable, View
which is implemented by the Path structure
extension Path : Shape
question: Why none of the Path extensions content are explicitly implementing any of the Shape protocol requirements? (if you unfold the ellipsis and check the content, you will notice that)
The same situation happens with the LinearGradient structure:
public struct LinearGradient : ShapeStyle, View, Sendable
it conforms to the protocol ShapeStyle, but in the LinearGradient content you don’t see any of the ShapeStyle requirements implemented: