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)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容