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

I am not sure about this question.

I don't know what I do inside the method or function but anyways here is the question: Given the struct below in the editor, we want to add a method that returns the person’s full name. Declare a method named fullName() that returns a string containing the person’s full name. Note: Make sure to allow for a space between the first and last name.

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

func fullName(a b: String = 1) -> [Point] {
var results = [Point]()

}

1 Answer

Christian Mangeng
Christian Mangeng
15,970 Points

Hi Joshua,

I think you should review the videos about methods (or functions). Right now your code goes in a very different direction to what the task actually asks for. Some hints:

1) the function needs to be inside the struct, otherwise it is not a method

2) the method should return a full name - which is a string - not an array of points (points do not make any sense here)

3) the method does not need to take any parameters, it may simply return firstName and lastName (separated by a space)

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

I'm not sure who 'downvoted' this response or why!? The response is correct and the content on point.

Joshua Nilsson I agree with Christian about reviewing the video about methods. I'm not sure where or why you have an array of Points in your code, or why there is a variable being declared inside. Neither really has anything to do with the method the task is asking for.

Understanding methods will be very important in Swift or any Object Oriented Programming, so have a read of what Christian wrote and review the video with those points in mind. Then give the challenge another go.

Keep Coding! :dizzy:

Jason