英文:
Why you not use an open keyword with structs in swift?
问题
到处都在谈论只有 open/public
关键字的 classes
,所以如果 Swift 的专家能够提供带有示例的令人满意的答案,那将是很棒的。
例如:我们可以在类中这样做,但在结构体中不要这样做!
open class Animal {
var name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
}
英文:
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
}
}
答案1
得分: 3
open
与结构体无关,因为它们不具有继承性。public
与模块外部的可见性相关,因此适用于所有类型。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论