-4

everywhere talk about only classes with open/public keyword so it would be great if swift experts can provide satisfying answers with an example.

for eg: we can do this in class but don't do it in the struct!

open class Animal {
    var name: String
    var age: Int
    
    init(name: String, age: Int) {
        self.name = name
        self.age = age
    }
}
yagnik suthar
  • 151
  • 2
  • 13

1 Answers1

3

open is irrelevant to structs, since they don't have inheritance. public relates to visibility from outside the module, so it is relevant to all types.

jrturton
  • 118,105
  • 32
  • 252
  • 268