Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift 2.0 Complex Data Structures Adding Instance Methods

My code will not compile. Can someone help me?

I'm a little confused with this code challenge.I don't understand why my code will not compile. This may not be related to the question I just asked but I want to know why the parentheses after getFullName are empty.

Helgi Helgason
Helgi Helgason
7,599 Points

I'm learning too so this might not make sense but as far as I know it's empty since the function doesn't take in any parameters but uses the stored properties inside the struct or Structure..... when you call the struct in which getFullName is a method you pass in the values for first and last name.

1 Answer

Without know what code you've tried, I can show you how to solve the Challenge but I can't direct you on where you went wrong;

struct Person {
    let firstName: String
    let lastName: String
func getFullName() -> String {
return "\(firstName) \(lastName)"
}
}

let aPerson = Person(firstName: "Fahiye", lastName: "Abdi") 
let fullName = aPerson.getFullName()

To answer your question about getFullName(), the parentheses are empty because the function isn't taking any arguments when it's called.

The reason for this is that the information it needs - the firstName and lastName of the Person object - are already defined when the Person object is created. The getFullName() function is just reading information from the instance of the Person object you created earlier.

Hope that helps, let me know if you have any other questions about this Challenge!