Swift枚举语法,结构体语法

enum CompassPoint {
    case north
    case south
    case east
    case west
}
var directionToHead = CompassPoint.west
 print(CompassPoint.east.hashValue)  //2

使用 Switch 语句匹配枚举值

directionToHead = .south
switch directionToHead {
    case .north:
        print("Lots of planets have a north")
    case .south:
        print("Watch out for penguins")
    case .east:
        print("Where the sun rises")
    case .west:
        print("Where the skies are blue")
}

结构体

struct Resolution {
    var width = 0
    var height = 0
}
print(Resolution().width) //0

let name = Resolution.init(width:4, height: 5)
var hd = Resolution(width: 1920, height: 1080)
hd.width = 2088

print(name.width)

你可能感兴趣的:(Swift枚举语法,结构体语法)