Structure, Protocol, and Class in Swift Language

What is Swift?

what’s the difference between a Struct, a Prototype, and a Class?

  1. Protocols function similarly to interfaces.
  2. Classes are classes, like in Java/Android and pretty much any other language.
  3. Structs are similar to classes, but when sent from one variable/function to another, they are passed by value (copied). If you’re acquainted with C#, you’ll notice that it uses structs in a similar way.

1. Class

  1. The properties of one class are passed down to another class through inheritance.
  2. Typecasting allows the user to check the type of a class at runtime.
  3. Deinitializers are responsible for freeing up memory resources.
  4. The class instance might have several references thanks to reference counting.

2. Structure

  • properties
  • methods
  • subscripts
  • initializers
  • protocol conformances
  • extensions

2. Protocol

Class vs Structure

  1. Create properties to store data.
  2. Define the methods that will be used to offer functionality.
  3. Subscript syntax is used to define subscripts and provide access to their values.
  4. To set up their starting state, define initializers.
  5. Be extended in order to expand their capabilities beyond what is provided by default.
  6. Conform to protocols in order to deliver a given level of standard functionality.

Class vs Protocol



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store