Someone is sitting by the beach thinking of purpose vs conformance.
This is an example of purpose grouping.
Keep this in mind: You are coding an
Say it again. You are coding an
String out of the box functions
First, what does the String type offer? Paste this code into Playgrounds. Playgrounds is a GREAT way to test concepts and play with options.
See -> Swift String Documentation
I need a Translate function!
But what if you want to translate your string into Pig Latin.
Swift does not provide a built-in method to do this.
🤮 Not very Swifty
This works! 🥳🥂 But, this function is not very swifty. 🤮
Instead this is the business case for extending the functionality of
Because it's an
I totally understand where you're coming from. When delving into complex topics like protocols, extensions, conformance grouping, and purpose grouping, it's natural to feel overwhelmed.
Protocols are essentially sets of rules that devices or systems follow to communicate effectively. Extensions often enhance or expand upon these rules. Conformance grouping and purpose grouping are ways to categorize and organize these rules and extensions.
Take it step by step, and don't hesitate to ask specific questions. We're here to help you navigate this complexity. You're not alone in your confusion, and with time and guidance, it will start making more sense. Keep asking questions, and you'll get there
What is Conformance?
Swift boffins use the term conformance to indicate that a
Think of it in other terms. In his CS193p course Paul Hegerty describes protocols as a behaviour. Instead of saying conformance (which may be abstract) try substituting Behaves Like
An example might be you have a
Now sort them!
The compiler will complain that you cannot sort the
Protocols to the Rescue
This is where protocols come in handy. On their own, how do you compare one fruit (apple) to another (kiwi) ? How would you sort them? By calories? By color? Alphabetically?
SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.