Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Anthia Tillbury
Anthia Tillbury
3,388 Points

Standard Library Protocols: Can Do, Is A and Can Be definitions?

In the second video of the Protocols module for Swift (Standard Library Definitions) three main definitions are used to break down the standard protocols in Swift:

ā€¢ Can Do ā€¢ Is A ā€¢ Can Be

For the first example a static function is first introduced, it used in with the Equatable Protocol included in Swifts Library to compare types, not entire instances.

How does this related to "Can Do"?

Can do what? Can compare?

The second example makes even less sense to me as it crosses the wires of the module before explaining inheritance within Protocols and "Is A" would relate to type (Class) inheritance, while protocol was labelled as "Composition".

But now it's reversed on a whim (Passan admits this) and it's quite confusing?!

Referred to only fleetingly as modelling familiar "Base Types" the video moves on, so I'm not quite sure what this refers to, I don't have a firm understand of it and as Passan made it up I'm unlikely to find it anywhere else.

Lastly is the Can Be, which is easier to follow as the example models along the simple lines of conversion; where one thing can be another e.g. a number can be converted to a string with the CustomStringConvertable protocol.

However the explanation of naming convention (Swift 4 is now the present release at the time of writing, but at the video was made c.2015 at the time where a transition between Swift 2 to Swift 3 was incomplete) where nouns are used to model the identity of a protocol's name, but this seems to only apply to the final name, not the prefix camel humps, which isn't made clear enough I think.

So, can anyone expand on Is A in regard to Standard Library Protocols because the video didn't explain it and I am still a little lost on Can Do e.g. how is the equality operator a Can Do operation?

Thanks!