protocol in swiftUI

I've been reading the 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 diving into the Swiftui documentation I noticed that Shape is a protocol

public protocol Shape : Sendable, Animatable, View 

which is implemented by the Path structure

extension Path : Shape 

Why none of the Path extensions content are explicitly implementing any of the Shape protocol requirements?

such as role, layoutDirectionBehavior, sizeThatFits, offset, intersection, union, and so on!

Answered by jlilest in 788770022

Apple's actual implementation code isn't going to show in xcode. The only thing that will be visible is the API.

Could you tell from where you extracted the screenshot with Path extension ? What is inside the ellipsis ?

from xCode, by pressing the command + click on the Path{...} instance. if you unfold the ellipsis and explore the fields, you will see that there are definitions not implemented from the protocol.

Apple's actual implementation code isn't going to show in xcode. The only thing that will be visible is the API.

Accepted Answer

Thanks for the clarifications, I will assume that it's a close source and that Protocols are indeed appropriately implemented in code behind

protocol in swiftUI
 
 
Q