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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Batuhan Dogan](https://uploads.teamtreehouse.com/production/profile-photos/9009182/micro_coder.god.jpg)
Batuhan Dogan
2,587 PointsBeginning Protocol code challenge #2
Can you guys help me with this? the problem is when I'm getting to "var somePerson: String and Int" and I don't know how should I say it.
protocol User {
var name: String { get }
var age: Int { get set }
}
struct Person {
let name: String
let age: Int
var somePerson: String, Int {
return "\(name) \(age)"
}
}
let somePerson = Person(name: "Batuhan", age: 19)
Person.somePerson
2 Answers
![Martin Wildfeuer](https://secure.gravatar.com/avatar/1d8de1e8e193bb39539e624618de9c60?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Martin Wildfeuer
Courses Plus Student 11,071 PointsHey there!
almost there! The person struct in your code did not add the protocol conformance. Moreover the somePerson
variable is invalid syntax, type should be String for what you want to achieve. However, this is not needed with this challenge. Also beware, although you can print out variables in Playgrounds like this: Person.somePerson
, this is actually invalid on normal code, as it provides no functionality at all. The following should work:
protocol User {
var name: String { get }
var age: Int { get set }
}
// Struct Person has to conform to protocol User
// The protocol a class or struct adheres to is defined
// with a colon as here
struct Person: User {
let name: String
let age: Int
}
let somePerson = Person(name: "Batuhan", age: 19)
Hope that helps :)
![Dean Kreseski](https://secure.gravatar.com/avatar/7e3c02eca13a383f77a8ae0b742687e0?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Dean Kreseski
2,418 PointsIf you change the two properties inside of the struct to variables instead of let constants it will work. hope this helps.
Batuhan Dogan
2,587 PointsBatuhan Dogan
2,587 Pointsthanks sir
Batuhan Dogan
2,587 PointsBatuhan Dogan
2,587 PointsI think I'm still doing something wrong.
protocol User { var name: String { get } var age: Int { get set } }
struct Person { let name: String let age: Int }
let somePerson = Person(name: "Batuhan", age: 19)
Batuhan Dogan
2,587 PointsBatuhan Dogan
2,587 PointsIt still doesn't work can you help me?