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 Protocols in Swift Protocol Basics Conforming to a Protocol

Bob Clanfield
Bob Clanfield
2,372 Points

I can't tell if this is bad code or SwifLlint issues. Any insights?

Been on a trip around the universe, trying to get this code to work and keep coming back to this syntax, thinking it's correct because Xcode compiles. Is it bad code or perhaps a SwiftLint issue?

protocols.swift
protocol User {
    var name: String { get }
    var age: Int { get set }
}

struct Person: User  {
    var name: String
    var age: Int
}
let  somePerson = Person(name: "X", age: 0)

7 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,541 Points

Hi Bob,

Jeff McDivitt is correct in that your code just has a spacing error. The problem is on this line:

let  somePerson = Person(name: "X", age: 0)

If you look, the variable somePerson is grey instead of blue. This is because there is an extra space after the let keyword. Once you delete a space, you code passes too.

Just an FYI for you guys, in case you were wondering why. :smiley:

Keep Coding! :dizzy:

Jeff McDivitt
Jeff McDivitt
23,970 Points

Hi Bob -

Your code is correct, if it is not letting you pass the challenge try refreshing your browser and also clearing the cache

protocol User {
    var name: String { get }
    var age: Int { get set }
}

struct Person: User {

    var name: String
    var age: Int
}

let somePerson = Person(name: "Jeff", age: 35)
Bob Clanfield
Bob Clanfield
2,372 Points

Hi Jeff, Thank you for responding. I've tried reloading and shutting down Safari. I even tried signing in with an Opera browser. The result is always comes back as ⓧ Bummer!

Jeff McDivitt
Jeff McDivitt
23,970 Points

Just for the heck of it, try pasting in my code

Bob Clanfield
Bob Clanfield
2,372 Points

Your code passed the challenge

Jeff McDivitt
Jeff McDivitt
23,970 Points

Probably just some spacing or something; sometimes the treehouse code editor can be a pain

Bob Clanfield
Bob Clanfield
2,372 Points

That was the best case scenario Many Thanks ¯_(ツ)_/¯ ॐ