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

Initializing vs. Creating an object

Hi Treehouse!

I'd like to know why it's important to implement the init method when creating instances of structs/classes. How is it different from creating objects directly by passing in arguments?

let someObject = someStruct(<arguments>)

vs

let someObject = someStruct.init(<arguments>)

Don't these achieve the same thing? Please help clear this up!

2 Answers

Anjali Pasupathy
Anjali Pasupathy
28,883 Points

To my knowledge, these are exactly the same thing. I think someStruct(<arguments>) calls someStruct.init(<arguments>). Creating an object, in this context, is the same thing as initializing it.

Thanks for the response! I'm confused as to why we need the init method though...