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

Marcel Barthold
Marcel Barthold
1,640 Points

My Code is working in the playground but I get an error in the code challenge. What's wrong?

struct Person { let firstName: String let lastName: String }

func getFullName(name: Person) -> String { let fullName = name.firstName + " " + name.lastName return fullName }

var marcel = Person(firstName: "Marcel", lastName: "Barthold") getFullName(marcel)

structs.swift
struct Person {
    let firstName: String
    let lastName: String
}

func getFullName(name: Person) -> String {
    let fullName = name.firstName + " " + name.lastName
    return fullName
}

1 Answer

Hi Marcel,

Code that works in the playground isn't subject to the tests the challenges need to pass. A playground just applies Swift syntax tests.

Here, the challenge wants you to create a function as part of the struct. That would look like:

struct Person {
    let firstName: String
    let lastName: String

    func getFullName() -> String{
      return self.firstName + " " + self.lastName
    }
}

I hope that helps.

Steve.