/**
结构体的实例化和成员访问
*/
struct Rect {
var width: Double = 5.0
var height: Double = 6.0
}
var rect: Rect = Rect()
// 访问成员变量
rect.width = 10
rect.height = 10
print("----------------->")
print(rect)
// (Rect #1)(width: 10.0,height: 10.0)
var rect1 = Rect()
print("----------------->")
// 初始值
print("rect1==\(rect1)")
rect1.width = 100
rect1.height = 101
print("----------------->")
print("rect1==\(rect1)")
// (Rect #1)(width: 100.0,height: 101.0)
原文链接:https://www.f2er.com/swift/322431.html