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 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,860 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 ¯_(ツ)_/¯ ॐ