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

help me with this bummer!!

where am I doing wrong?

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

struct Person{ var name: String var age: Int self somePerson = Person }

let Person = somePerson(name: "Batuhan", age: 19)

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

struct Person{
var name: String
var age:  Int 
self somePerson = Person
}

let Person = somePerson(name: "Batuhan", age: 19)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! First, the self somePerson = Person is not needed and you can safely remove that line. Secondly you have a struct named Person which currently conforms to no protocols but should conform to the User protocol. To make something conform to a protocol we use a semicolon and then the name of the of the protocol. Like so struct myStruct : myProtocol. That would be a struct named myStruct which conforms to myProtocol. On the final line you are supposed to declare a constant named somePerson and assign it a new instance of Person. However, you've declared a constant named Person and tried to assign it a new instance of something called somePerson. You've simply gotten this line a bit backwards.

I feel like you can get it with these hints, but let me know if you're still stuck! :sparkles:

still can't do it:(

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

struct secondStruct : Person { var name: String var age: Int let somePerson = Person }

let somePerson = Person(name: "Batuhan", age: 19)

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Batuhan Dogan Not quite! Now you've changed the name of the struct to secondStruct and made it conform to the Person protocol, which doesn't exist.

We're looking for something like:

protocol User {
   // specifications for User
}

struct Person : User {
  // specificications for Person
}

let somePerson = Person(name: "Batuhan", age: 19)

After we write the name of the struct we then write a colon and the name of the protocol it should conform to: struct Person: User. This is a Person that conforms to User.

Give it another shot! :sparkles: