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

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: