1. Creating Structs
  2. Computed Properties
  3. Property Observers
  4. Methods
  5. Mutating Methods
  6. Properties and Methods of Strings
  7. Properties and Methods of Arrays

1. Creating Structs

It is a value type.

It is basically a class where there is member wise initializing automatically.

And the orignal data is unaffected

simple example

struct Sport {
    var name: String
}
var tennis = Sport(name: "Tennis")
print(tennis.name)
tennis.name = "Lawn tennis"
print(tennis.name)

output

Tennis Lawn tennis

another example you don’t have to initialise self. variable in it, a Struct will automatically do that.

Now consider the below example, If this was done in a class then sean variables name would’ve changed to Joe and that would be it. But since it’s a struct, data for joe and sean is same although existing independently. That is why we are able to changes Joe’s variable data name to “Joe”.