Static vs. Class keywords in Swift

Moussa Hellal
2 min readSep 23, 2021

--

Static and Class are very similar in Swift but are different in a way.

Similarities:

Static and Class both makes a variable or a function a Type method whenever used.

an example of this would be:

By this we understand that Type Methods are those which we can call directly without the need of creating an instance of the class.

Simply right?.

Differences:

The differences takes a place when we are going to inherit our Class Human in a new class let’s call it SuperHuman

Specifically when we try to override the Property name which is Static Xcode will yell at you telling you that you can not override the static property name.

So simply put static cannot be overridden when inherited.
Whereas class marked methods and properties can be overridden.

Moreover:

Differences on types of properties:

the static keyword can be applied on both stored and computed properties.

the class keyword can be applied only on computed properties.

Differences on Classes and Structs

the static keyword is allowed on both Classes and Structs.

the class keyword is only allowed to be used on Classes.

We have made it to the end. Yass!😁 Thank you 🙏
Hope you have learned something new today.

Share and Retweet if you have found this helpful.

Make sure to follow me on Twitter: 👇👇👇

Until the Next one!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response