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 Complex Data Structures Adding Instance Methods

richard barnes
richard barnes
2,949 Points

Some help, tearing my hair out on this one.

I can't figure out what I'm doing wrong, I've spent the last couple of days going through solutions and answers and I can't figure out what my error is. any help appriciated

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

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

let aPerson = Person(firstName: "John", lastName: "Smith")
let fullName = aPerson.getFullName()

2 Answers

Alphonso Sensley II
Alphonso Sensley II
8,514 Points

Hi Richard, You've got all the code correct. I may have found whats causing you not to pass though. I think it's just the challenge being finicky because you didn't use their specified names for your constants. The challenge says call the method fullName(), you named it getFullName(). Also in the instances of the Person struct; your let fullName = aPerson.getFullName(). Should be let myFullName = aPerson.fullName().

again you've got everything right. Just didn't enter the exact names as the challenge asked. lol I know kind of annoying!

richard barnes
richard barnes
2,949 Points

Thanks a lot, thought I must have missed something simple