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 Intermediate Swift 2 Value Semantics, Type Methods and Inheritance Type Methods

Paul M
Paul M
16,370 Points

What does "static" mean in Swift?

In the code he worked on, he added static before a constant and a function. But what does it really do, and what are the benefits and downsides of using static?

2 Answers

Chase Marchione
Chase Marchione
155,055 Points

Hi Paul,

The static keyword is used to indicate that a method is a type method. Type methods contrast with instance methods, in that:

  • Instance methods are called on an individual instance of one unique/chosen type.
  • Type methods are called on the actual type, in and of itself.

Additional notes:

  • Subclasses can override class methods; however, they cannot override static methods.
  • Concerning constants: similarly, static constants should not be overridden, as opposed to non-static constants.

A page that may prove useful: http://sketchytech.blogspot.com/2014/09/swift-rules-of-being-static-xcode-6-gm.html.

Hope this helps!

thanks a lot