我刚学swift,最近发现变量或常量需要用初始数字或初始化器初始化,但在struct中不需要初始化?
最佳答案
他们确实需要。
来自 Swift 语言指南:
Classes and structures must set all of their stored properties to an appropriate initial value by the time an instance of that class or structure is created. Stored properties cannot be left in an indeterminate state.
You can set an initial value for a stored property within an initializer, or by assigning a default property value as part of the property’s definition.
关于swift - 为什么swift中变量需要在类中初始化,而在struct中不需要初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34198828/