0%

Swift 014 Structs

結構

Struct可以將多個元素包裝再一起,一但創建了結構,就可以通過下面方式讀取對應屬性。

1
2
3
4
5
6
7
8
9
10
11
struct Point {
var x: Int
var y: Int
}

let pointA = Point(x: 1, y: 2)
let pointB = Point(x: 3, y: 4)

print("\(pointA.x)")
print("\(pointA.y)")