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
philip williams
5,991 Pointsprotocols not conforming but i can't see why? Can anyone help?
//: Playground - noun: a place where people can play
import UIKit
protocol Persontype {
var firstName: String { get }
var middleName: String { get }
var lastName: String { get }
func fullName() -> String
}
extension Persontype { func fullName() -> String { return "(firstName) (middleName ?? " ") (lastName)" } func greeting()-> String { return "hi, " + fullName() }
}
struct User: Persontype {
let firstName: String
let middleName: String?
let lastName: String
func greeting() -> String {
return "Hey there, " + fullName()
}
}
let someUser = User(firstName: "Pasan", middleName: nil, lastName: "Premaretne") let anotherUser: Persontype = User(firstName: "Philip", middleName: nil, lastName: "Williams")
someUser.greeting() anotherUser.greeting()
2 Answers
Anjali Pasupathy
28,883 PointsIt's a small error. You just need to make middleName an Optional String in your Persontype protocol.
I hope this helps!
philip williams
5,991 PointsThank you Anjali
Anjali Pasupathy
28,883 PointsYou're welcome!