Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Hello,

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.