|
This page really confuses me. It's so abstract to me, I barely know what protocols are yet, same goes for extensions, and I do not see the correlation between them, or what conformance grouping and purpose grouping really are. Basicaly, I'm overwhelemd. Help, anyone? Thanks. |
|
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 functionsFirst, 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 SwiftyThis works! 🥳🥂 But, this function is not very swifty. 🤮 Instead this is the business case for extending the functionality of
Keep coding!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 |
|
Part Deux
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 Sorting FruitAn example might be you have a
Now sort them! The compiler will complain that you cannot sort the Protocols to the RescueThis 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 Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.