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's correct but its not being accepted. It works in Xcode. Maybe I have the right solution for the wrong question?

Bummer! The value being assigned to fullName must be a result of calling the instance method getFullName()

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

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

let aPerson = Person(firstName: "Mazen", lastName: "Wasel")
let fullName = aPerson.getFullName()
Kyle Lambert
Kyle Lambert
1,969 Points

Hi Mazel, you're code looks good and it runs in my complier. Try refreshing your browser. Also to make it easier to write, inside the method, their is no need to declare a constant named fullName you can achieve the same result with just coding return "\(firstName) \(lastName)"

Should look like this, but either way is correct.

struct Person {
    let firstName: String
    let lastName: String

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

let aPerson = Person(firstName: "Mazen", lastName: "Wasel")
let fullName = aPerson.getFullName()

2 Answers

Brian Steele
Brian Steele
23,060 Points
struct Person {
    let firstName: String
    let lastName: String

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

    }
}

let aPerson = Person(firstName: "Mazen", lastName: "Wasel")
let fullName = aPerson.getFullName()

Your code does compile in XCode, but some of the challenges are a little picky about the exact approach. This should get you passing.

Thank you Brian.

It seems that the problem was the brackets around String...

it did not accept the following: func getFullName() -> (String) {

but it accepted the following: func getFullName() -> String {

Does anyone know if the brackets are correct or incorrect syntax? or are they necessary at all or only in some cases?

Brian Steele
Brian Steele
23,060 Points

Not necessary unless you are returning a tuple

Makes sense, Thanks!