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 trialThomas Katalenas
11,033 Pointstried everythin, computed property
struct Friend: FullyNameable {
let firstName: String
let middleName: String
let lastName: String
var fullName: String { /// computed property of Friend Struct.
return “\(firstName) \(middleName) \(lastName)”
}
}
let friend = Friend(firstName: “Taylor”, middleName: “Aliston”, lastName: “Swift”) // this is instance, so we can add computed property to protocol through stuck Friend.
friend.fullname
protocol UserType {
var name: String { get }
var age: Int { get set } // is this an example of a specific instance property that protocols require conforming types, or is this just a conforming type.
}
struct Person: UserType {
let Name: String
let Age: Int
var UserType: String{ // trying to use a computed property of Person struct so I can add to instance below, whats going wrong here
return (\(Name) \(Age))
}
let somePerson = Person(Name: "George", Age : 32)
—————
protocol UserType {
var name: String { get }
var age: Int { get set } // is this an example of a specific instance property that protocols require conforming types, or is this just a conforming type.
}
struct Person: UserType {
let Name: String
let Age: Int
var name: String{ // trying to use a computed property of Person struct so I can add to instance below, whats going wrong here
return "\(Name)"
}
var age: Int { // is there away to return both these at same time like we did with fullName returning firstName, middleName and lastname.
return "\(Age)"
}
}
let somePerson = Person(Name: "George", Age : 32)
———————
swift_lint.swift:8:8: error: type 'Person' does not conform to protocol 'UserType'
struct Person: UserType {
^
swift_lint.swift:5:7: note: protocol requires property 'age' with type 'Int'
var age: Int { get set } // is this an example of a specific instance property that protocols require conforming types, or is this just a conforming type.
^
swift_lint.swift:16:9: note: candidate is not settable, but protocol requires it
var age: Int { // is there away to return both these at same time like we did with fullName returning firstName, middleName and lastname.
^
swift_lint.swift:17:16: error: cannot convert return expression of type 'String' to return type 'Int'
return "\(Age)"
I want to do a computed property, although I can get the answer right it is not needed with specification, can you help I have several tries up there
protocol UserType {
var name: String { get }
var age: Int { get set } // is this an example of a specific instance property that protocols require conforming types, or is this just a conforming type.
}
struct Person: UserType {
let name: String
let age: 32
}
// trying to use a computed property of Person struct so I can add to instance below, whats going wrong here
// is there away to return both these at same time like we did with fullName returning firstName, middleName and lastname.
let somePerson = Person(name: "George", age : 32)
1 Answer
Jason Anders
Treehouse Moderator 145,860 PointsHey Thomas,
In the top code snippet, I'm going to guess that you copied it from a word processor, as the many of the quotation marks (both singles and doubles) are showing as 'fancy quotes', which are not recognized by the compiler. You will need to go in and delete and re-type all the quotation marks. If you look at the code that is posted in your question, you will see the quotes being 'hi-lighted' ... this means something is wrong.
Also there is one return statement that is missing quotes all together.
Try tidying up those and see if you can get it to compile for you.