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 Generics in Swift Generics and Protocols Protocol with Associated Type

Vladimir Taranik
Vladimir Taranik
4,841 Points

I can't understand this at all

Can someone tell the solution for this task? I will be very happy!

Vladimir Taranik
Vladimir Taranik
4,841 Points

Can't understand this task, how to write this code:

"Let's get some practice in creating a protocol with an associated type so we're familiar with the syntax.

Declare a protocol named ConfigurableRow with an associated type object.

Add a single requirement to the protocol - a function named configure with a single argument of type Object. Give the function an external name of with and local name of object."

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points


To name an associated type, this is what you need to do.

protocol ConfigurableRow {
  associatedtype Object

  func configure(with object: Object)

Hope this helps you.