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

John Conner
John Conner
950 Points

I am not sure what I am over thinking. But I am pretty sure I have completely

Again, I am not sure what is causing me the most issue. Logic or syntax or [] opposed {} and (). I get what an instance is, data that is passed through the structure/function. The method is the operations performed on the data. an instance method is a type of method used to manipulate a data set to achieve new/different results.

structs.swift
 struct Person {
        let firstName: String
        let lastName: String
        func fullName() -> [String] {

        }
return "/firstName" + " /lastName"}
}
let fullName = (firstName: "John", lastName: "Conner")

1 Answer

nickyp
nickyp
2,140 Points

Below is a working solution:

struct Person {
    let firstName: String
    let lastName: String
    func fullName() -> String {
      return firstName + " " + lastName
    }
}

The challenge asks you to "Declare a method named fullName() that returns a string containing the person’s full name"

  • First, you specified that a method fullName() will return an Array of type String (an Array containing Strings). The challenge asks you to return a String.
  • Second, the return statement should be inside the body (code block) of the fullName() method (within {}).
  • Third, when you type - return "/firstName" + " /lastName"}, you are trying to use String Interpolation, but in this case it isn't necessary because the firstName and lastName properties are already of type String.

Here are some links that will help you better understand these concepts: Strings and Characters, Code Blocks