Conclusion
Conclusion
In this lesson, you learned some of the basics of protocols and how to use them, such as defining common interfaces and specifying the interactions between different parts of your code. Protocols are a tool in your coding backpack that’s similar to inheritance, but each one has different use cases. You should be sure to use the right tool for the job, depending on your circumstances.
In this lesson, you learned:
- How to define a protocol in Swift with mutable and immutable properties and functions.
- How to create and use a type that conforms to a protocol.
- How protocols compare to inheritance, where they differ and why you might prefer protocols over inheritance in some scenarios.
- How the compiler can help ensure the types that implement your protocols are correct.