Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Object-Oriented Swift Complex Data Structures Adding Instance Methods

Tyler Dotson
PLUS
Tyler Dotson
Courses Plus Student 1,740 Points

I am a bit lost someone please help with declaring a method.

Is method similar to a function if so am I doing this correctly and do I need so specify if the return value with will be a (String, String). Am I also able to use the constants in the struct as parameters in the function.

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

    func fullName()
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! The only difference between a method and a function is that a method is part of the class/struct and defined inside it. All methods are functions, but only some functions are methods :smiley:

So yes, you will have to specify a return type. The same rules that apply to functions apply to methods as methods are simply a subset of functions.

Hope this helps! :sparkles: