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 trialNan Wang
10,036 PointsChanllenge Task in Swift 3 Protocol
I can't pass this challenge, can anyone help me?
protocol User {
var name: String { get }
var age: Int { get set }
}
struct Person:User {
let person_Name:String
let person_Age:Int
var name:String {
return "\(person_Name)"
}
var age:Int {
return person_Age
}
}
2 Answers
Andrew Boryk
15,916 PointsHello!
It seems that the challenge is asking for Person to conform to the protocol User.
You started off great with adding:
struct Person: User
User has two variables: 'name' and 'age'. Thus, Person must conform to those variables by including 'name' and 'age' in it's struct. This is done like so:
protocol User {
var name: String { get }
var age: Int { get set }
}
struct Person: User {
var name: String
var age: Int
}
Finally, you test everything with an instance of Person named 'somePerson'
let somePerson = Person(name:"Test", age:21)
Hope this helps!
michaellesniak
10,443 PointsWow... I forgot to add ": User" have struct Person.
Thanx!