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

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: