swift Enum 笔记

19. December 2015 Swift 0

import Cocoa

 

var str = “Hello, playground”

enum Game{

   case win

   case lose

   case draw

}

var youscore = 100

var enemyscore = 100

var theGameEnding:Game

let ga = Game.win

ga.hashValue

 

if youscore > enemyscore

{

   theGameEnding = Game.win

}

else if youscore == enemyscore

{

   theGameEnding = Game.draw

}

else {

   theGameEnding = Game.lose

}

switch theGameEnding{

case .win :println(“you win”)

case .lose:println(“you lose”)

case .draw:println(“you draw”)

}

enum Month : Int{

   case J = 1,Feb,Mo

}

 

let cur:Month = .Feb

let sss = Month.Feb.rawValue

cur.rawValue

let next = Month(rawValue: 1)

next!.hashValue

 

// if let 可以解包多个可选类型,用逗号分开

var A = Set<<span style=”font-variant-ligatures: no-common-ligatures; color: #703daa”>String>()

A.insert(“li”)

A.insert(“jian”)

var B:Set<<span style=”font-variant-ligatures: no-common-ligatures; color: #703daa”>Int> = [2,3,4]

var C = Set<<span style=”font-variant-ligatures: no-common-ligatures; color: #703daa”>Int>([4,5])

C.insert(6)

C.contains(2)

var q = [2,3,4]

var t = q

var u = t

q[1] = 100

q.append(10)

u.append(9)


Leave a Reply

Your email address will not be published. Required fields are marked *