日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【swift3.0】【枚举定义的不同方式】

發(fā)布時間:2025/3/20 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【swift3.0】【枚举定义的不同方式】 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??

貢獻(xiàn)作者 -【XJDomain】
博客XJ:? https://my.oschina.net/shengbingli/blog
GitHub直播地址:? https://github.com/lishengbing/XJDomainLive

XJ--01

> 定義字符串類型的枚舉

enum kBackgroundImageNameType : String {// 藍(lán)色<默認(rèn)>case navBarBg_04BEC6 = "navBarBg_04BEC6"// 橘色case navBarBg_FFAB6D = "navBarBg_FFAB6D"// 灰色case navBarBg_E7E7E7 = "navBarBg_E7E7E7" }

使用一:

kBackgroundImageNameType.navBarBg_04BEC6.rawValue

?

?

XJ--02

> 定義沒有類型的枚舉:

enum MethodType {case getcase post }

使用二:

let method = type == .get ? HTTPMethod.get : HTTPMethod.post

?

XJ--03

> 枚舉的完美解析:

// 1:枚舉類型的定義 enum MethodType {case getcase postcase putcase delete }enum MethodType1 : String {case get = "get"case post = "post"case put = "put"case delete = "delete" }// 2:創(chuàng)建枚舉具體的值 let type1 : MethodType = .get let type2 = MethodType.post// 3:給枚舉類型進(jìn)行賦值 // 如果枚舉沒有賦值的話是沒有值的,不像oc中默認(rèn)依次是0.1.2.3.... enum Direction : Int {case east = 0case west = 1case north = 2case south = 3 }let d : Direction = .east // 只有賦值才會有這種創(chuàng)建方式:可選類型 let d1 = Direction(rawValue: 1)// 4:枚舉類型定義方式二 enum Type {case get, post, put, delete } // 只針對Int類型,會自動為0.1.2.3 enum Type1 : Int {case get = 0, post, put, delete }let type111 = Type1(rawValue: 1) print(type111)

?

?

?

?

?

?

?

轉(zhuǎn)載于:https://my.oschina.net/shengbingli/blog/806307

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的【swift3.0】【枚举定义的不同方式】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。