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

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!