欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何使用swift枚舉定義

本篇內(nèi)容主要講解“如何使用swift枚舉定義”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“如何使用swift枚舉定義”吧!

創(chuàng)新互聯(lián)是一家專(zhuān)業(yè)提供定襄企業(yè)網(wǎng)站建設(shè),專(zhuān)注與網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)HTML5、小程序制作等業(yè)務(wù)。10年已為定襄眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。

枚舉定義

//枚舉定義
enum CompassPoint {
    case north
    case south
    case east
    case west
}

//常配合switch case使用
let directionToHead = CompassPoint.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")
}
/*
 Watch out for penguins
 */

枚舉遍歷

//枚舉遍歷
enum Planet: CaseIterable {
    case mercury, venus, earth, mars, jupiter, saturn, uranus, neptune
}

for planet in Planet.allCases {
    print(planet)
}
/*
 mercury
 venus
 earth
 mars
 jupiter
 saturn
 uranus
 neptune
 */

關(guān)聯(lián)值

//關(guān)聯(lián)值
enum Barcode {
    case upc(Int, Int, Int, Int)
    case qrCode(String)
}

func showBarcode(_ barcode: Barcode) {
    switch barcode {
    case .upc(let numberSystem, let manufacturer, let product, let check):
        print("UPC:\(numberSystem), \(manufacturer), \(product), \(check)")
    case .qrCode(let productCode):
        print("QR Code: \(productCode)")
    }
}

var productBarcode = Barcode.upc(1, 1, 1, 1)
showBarcode(productBarcode)
//UPC:1, 1, 1, 1
productBarcode = Barcode.qrCode("hello")
showBarcode(productBarcode)
//QR Code: hello

原始值

//原始值
enum ASCIIControlCharacter: Character {
    case tab = "\t"
    case lineFeed = "\n"
    case carriageReturn = "\r"
}

從原始值初始化

//從原始值初始化
enum RoleStatus: Int,CaseIterable {
    case run
    case jump
    case walk
    case idle
}

for i in 0...RoleStatus.allCases.count {
    print(RoleStatus(rawValue: i))
}
/*
 Optional(__lldb_expr_8.RoleStatus.run)
 Optional(__lldb_expr_8.RoleStatus.jump)
 Optional(__lldb_expr_8.RoleStatus.walk)
 Optional(__lldb_expr_8.RoleStatus.idle)
 nil
 */

遞歸枚舉(indirect)

//遞歸枚舉 (5+4)*2
indirect enum ArithmeticExpression {
    case number(Int)
    case addition(ArithmeticExpression, ArithmeticExpression)
    case multiplication(ArithmeticExpression, ArithmeticExpression)
}

let five = ArithmeticExpression.number(5)
let four = ArithmeticExpression.number(4)
let sum = ArithmeticExpression.addition(five, four)
let product = ArithmeticExpression.multiplication(sum, ArithmeticExpression.number(2))

func evaluate(_ expression: ArithmeticExpression) -> Int {
    switch expression {
    case let .number(value):
        return value
    case let .addition(left, right):
        return evaluate(left) + evaluate(right)
    case let .multiplication(left, right):
        return evaluate(left) * evaluate(right)
    }
}

print(evaluate(product))
//18

到此,相信大家對(duì)“如何使用swift枚舉定義”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!

新聞名稱(chēng):如何使用swift枚舉定義
分享URL:http://aaarwkj.com/article16/ihpegg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)網(wǎng)站內(nèi)鏈、搜索引擎優(yōu)化、網(wǎng)站策劃、標(biāo)簽優(yōu)化、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
不卡的av中文字幕在线播放| 亚洲天堂av一区二区在线| 一区二区三区av夏目彩春| 人妻少妇中文字幕在线播放| 国产精品乱码中文字幕| 亚洲中文字幕一区乱码| 香蕉视频欧美日韩国产| 精品视频中文字幕天码| 亚洲精品一二三区免费| 亚洲激情精品成人在线| 国产精品亚洲二区三区三州| 国产激情久久久久久影院| 91综合午夜精品福利| 人妻一区二区免费视频| 久久精品国产亚洲av麻豆她| 开裆丝袜高跟啪啪高潮av| 18禁超污网站免费观看| 日产极品一区二区三区| 91九色国产在线播放| 国产精品av在线网站| 91中文字幕精品一区二区| 毛片成人18毛片免费看| 日本 一区二区在线| 玩弄丰满熟妇班主任老师 | 日韩黄色大片免费在线观看| 国产一区二区三区婷婷| 日韩av一区二区三区在线| 成人福利午夜一区二区| 性激烈的欧美三级男同| 久久久久久国产精彩视频| 日韩伦理高清在线观看| 午夜性生活免费在线观看| 成人国产亚洲日本欧美| 成人偷拍自拍在线视频| 亚洲一区二区三区日韩欧美| 国产特级黄片免费观看| 亚洲欧美日韩成人在线| 尤物视频精品在线观看| 上海老熟女啪啪露脸高潮| 日韩不卡的在线视频| 蜜臀午夜精品视频在线观看|