It is a value type.
It is basically a class where there is member wise initializing automatically.
And the orignal data is unaffected
for 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”.
struct Developer {
var name: String?
var jobTitles: String?
var yearsExp: Int?
}
var sean = Developer(name: "Sean", jobTitles: "IOS Engineer", yearsExp: 5)
var joe = sean
joe.name = "Joe"
print(sean.name!)
print(joe.name!)
print("")
print(sean)
print(joe)
output
Sean
Joe
Developer(name: Optional("Sean"), jobTitles: Optional("IOS Engineer"), yearsExp: Optional(5))
Developer(name: Optional("Joe"), jobTitles: Optional("IOS Engineer"), yearsExp: Optional(5))