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

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!