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

Darcy Phillips
Darcy Phillips
4,087 Points

Swift 2 protocol conformance challenge not accepted

protocol PrettyPrintable {
    var prettyDescription: String { get }
}

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

    var prettyDescription: String {
        return "\(name), ID: \(ID)"
    }
}

The message I get is "Bummer! Make sure you extend User and conform to PrettyPrintable."

I think I've done that? It works in Xcode. I'm in Swift 3, but I'm sure my solution follows the format in the video.

Thanks for your help! Darcy

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

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

    var prettyDescription: String {
        return "\(name), ID: \(ID)"
    }
}

// Enter your code below

2 Answers

Moritz Lang
Moritz Lang
25,909 Points

Your code should work, but the task is to extend User. Maybe you have to write an extension on User and add the property there:

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), ID: \(ID)"
    }
}
Darcy Phillips
Darcy Phillips
4,087 Points

Yes of course, you are absolutely right. Thank you!