iOS Object-Oriented Swift Complex Data Structures Adding Instance Methods

Alice Muir
Alice Muir
1,357 Points

Hi there, I don't understand why this code won't pass the compiler?

struct Person {
    let firstName: String
    let lastName: String

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

let aPerson = Person(firstName: "Steve", lastName: "Hunter")
let fullName = aPerson.getFullName()
structs.swift
struct Person {
    let firstName: String
    let lastName: String

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

let aPerson = Person(firstName: "Steve", lastName: "Hunter")
let fullName = aPerson.getFullName()

Moderator edited: Markdown added so that code renders properly in the forums.

2 Answers

Jennifer Nordell
MOD
Jennifer Nordell
Treehouse Moderator

Hi there, Alice Muir! It looks like you're doing fantastic! However, as you've probably noticed, these challenges are very particular about certain things. In this case, it's having a problem with the method name and also with the final constant you declared.

It asks for the method to be named fullName, but you named it getFullName. On the second step, the challenge asks for the constant to be named myFullName but you named it fullName, which was supposed to be the name of the method :smiley:

Once I fix the naming of those two things, your code passes with flying colors! Hope this helps! :sparkles:

Alice Muir
Alice Muir
1,357 Points

Got it, thanks so much! :)