加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift的enum枚举类型介绍

发布时间:2020-12-14 02:09:33 所属栏目:百科 来源:网络整理
导读:声明枚举类型的几种方法和使用: 一: enum Direction{ case North case South case East case West};//简写如下enum Direction2{ case North,South,West,East}; 二: //申明一个枚举var d = Direction.North;var d2 = Direction.East;d2 = .South;//.South

声明枚举类型的几种方法和使用:

一:

enum Direction{
    case North
    case South
    case East
    case West
};
//简写如下
enum Direction2{
    case North,South,West,East
};
二:
//申明一个枚举
var d = Direction.North;
var d2 = Direction.East;
d2 = .South;//.South因为d2肯定是Direction枚举类型
//.South = Direction.South

//明确规定d3类型是Direction,.East就可以省略,同上远离
var d3 : Direction = .East;
var d4 : Direction = Direction.East;

switch d4 {
case .North:
    println("in north")
case .South:
    println("in south")
case .East:
    println("in east")
default:
    println("other")
}

//枚举类型一种,相似C
enum Couse : Int {
    case android = 1,ios,windowsphone,symbian
}

var c : Couse = Couse.ios;
let v = c.rawValue;//ios转换成int
println("v is: (v)");

var c2 = Couse(rawValue: 4)//根据索引返回枚举值
if c2 == Couse.symbian{
    println("is symbian");
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读