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 Intermediate Swift 2 Extensions and Protocols Protocol Conformance Through Extensions

Protocol Conformance Through Extensions

Hey! the error says: "Make sure you extend User and conform to PrettyPrintable"

What am I Doing Wrong! Typo?

protocols.swift
protocol PrettyPrintable {
    var prettyDescription: String { get }
}

struct User: PrettyPrintable {
    let name: String
    let ID: Int
    var prettyDescription: String {
        return "User name is \(name) and UserID is \(ID)"
    }

}

// Enter your code below

1 Answer

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Stuart,

you were on the right track but in this case you want to add additional functionality to the existing User struct by using an extension like you saw in the video before.

To do this you can use the extension keyword in combination with the struct you want to add the functionality to followed by the protocol you want to conform to:

protocol PrettyPrintable {
    var prettyDescription: String { get }
}

struct User {
    let name: String
    let ID: Int
}

// Enter your code below
extension User: PrettyPrintable {
  var prettyDescription: String {
    return "Name: \(name), ID: \(ID)"
  }
}

I hope that helps, good luck! :)

Oh, that's very helpful. Thank You!! :)