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

I don't understand why my code for the second part of the coding challenge is not working.

I don't understand why my code for the second part of the coding challenge is not working. When I run my code in Xcode, it works... My code is pasted below.

struct Person { let firstName: String let lastName: String

func getFullName() -> (String) {
    return "\(firstName) \(lastName)"
    }

}

let fullName = Person(firstName: "Billy", lastName: "Bob")

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

Hi Cody,

It seems to be working.

Maybe some issue in the Treehouse parser.

I assume it has to do with the brackets around String when returning the value. Normally you would use the brackets when working with Tuples.

So instead of writing

func getFullName() -> (String) {

use

func getFullName() -> String {

Here's the whole code from your example:

import Foundation

struct Person {
    let firstName: String
    let lastName: String

    func getFullName() -> String {
        return "\(firstName) \(lastName)"
    }

}

let person = Person(firstName: "Tom", lastName: "The Cat")

person.getFullName()

Here's the official reference for the function return syntax

1 Answer

Hm. I think I posted this wrongly. Please check the comment above for the answer :)