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

Trevor Justice
Trevor Justice
1,965 Points

struct Coding Challenge Help

Hello,

I'm new to programming and trying to complete this coding challenge using structs and methods. I'm working in my Xcode Playground, and have tried every variation of things I could think of to put inside fullName, yet I always get an error by return which reads ¨Unexpected non-void return value in void function¨. If anyone could explain to me why the code isn't working, and suggest a way to fix it, I would greatly appreciate it.

Thank you! Trevor

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

    func fullName(first: String, last: String) {
      let name = first + last

      return name
    }
}

1 Answer

You are attempting to return a string from a function that is expected to return Void(which means nothing). The function must be:

func fullName(first: String, last: String) -> String
Trevor Justice
Trevor Justice
1,965 Points

Thank you, I understand now!