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

Adding an instance

How do I add an instance to this method?

structs.swift
struct Person {
    let firstName: String
    let lastName: String
}
func getFullName(Full Name local: String)
{
    return firstname + lastname
}

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

The challenge wants you to create an instance of the struct. Creating an instance of the struct is simple, you have to use it's member wise initializer.

The second part of the challenge is asking you to create an instance of the struct Person, and provide its properties with any values you want. Then after you have that instance, you want to call the function you created on that instance and assign it to a constant.

struct Person {
    let firstName: String
    let lastName: String

 // Instance method that returns a full name from the struct's properties. 
    func getFullName()-> String {
    return "\(firstName ) \(lastName)"
    }
}

// Here we create the instance of the struct Person.
let aPerson = Person(firstName: "Your Name", lastName: "Your Last Name")

// Here we call that method we created on the instance aPerson. 
let fullName = aPerson.getFullName()

I hope this helps you.. Good luck

Ghaith Ali
Ghaith Ali
3,134 Points

Im not sure but I think your problem is having a space between Full and Name, furthermore, since it is a parameter name so the convention is to write them in camelcase casing (fullName). Hope this helps.:)

Edit: Another problem I can see with your code is that you are not returning anything in the method, it should return a String type

func getFullName(fullName local:String)->String { //function code }