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 trialMatthew Ingram
Courses Plus Student 4,718 PointsI am very lost
I don't understand this at all. Why call the instance twice?
struct Person
{
let firstName: String
let lastName: String
func fullName(theName name: String) -> [String]
{
var results = [Person]()
let Person = ("\(firstName) \(lastName)")
return results
let aPerson = Person(firstName: "Callam", lastName: "Ingram")
}
}
let myFullName =
2 Answers
Dhanish Gajjar
20,185 PointsHopefully this will clear things out
struct Person {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
let aPerson = Person(firstName: "John", lastName: "Appleseed")
let myFullName = aPerson.fullName()
Will DeBernardi
2,763 PointsThat last line is happening because to actually utilize the method that you defined within the struct, you need to apply it to an instance, because that method doesnt actually exist out side of the struct. So when you write:
let myFullName = aPerson.fullname()
You are actually applying the method to the parameters defined from aPerson.
Matthew Ingram
Courses Plus Student 4,718 PointsThank you that makes much more sense
Matthew Ingram
Courses Plus Student 4,718 PointsMatthew Ingram
Courses Plus Student 4,718 Pointsthank you!
Matthew Ingram
Courses Plus Student 4,718 PointsMatthew Ingram
Courses Plus Student 4,718 PointsWhats happening on the last line of code?
let myFullName = aPerson.fullName()