How to create and use enums – Swift for Complete Beginne
จาก enumeration , เป็น set of name ที่ถูกสร้าขึ้น และใช้ใน code
enum ไม่ได้มีความหมายพิเศษอะไรใน swift

var selected = "Monday";
selected = "Tuesday";
selected = "January";
selected = "Friday ";

มันอาจจะทำให้เราผิดได้ เพราะหลัง friday มีกับไม่มี space ก็แตกต่างกัน
การทำ enum เหมือน boolean จะบังคับให้มีแค่ true , false

enum Weekday {
    case monday
    case tuesday
    case wednesday
    case thursday
    case friday
}  

ใส่ค่าที่เราต้องการจัดระเบียบ ต่อไป ถ้าเรียกใช้ january ก็จะเตือนขึ้นมา

var selected = "Monday"
selected = "Tuesday"
selected = "January"
selected = "Friday "

enum Weekday {
    case monday, tuesday, wednesday, thursday, friday ถ้าเยอะๆ ก็ใช้ commaแบบนี้แทน 
}

var day = Weekday.monday
day = .tuesday    ย่อเป็นจุดแทนก็ได้ 
day = .friday

Discover more from อรรถพรคลินิก ศัลยกรรมตกแต่ง Attaporn Plastic Surgery clinic 阿塔蓬博士,曼谷整形外科医生

Subscribe now to keep reading and get access to the full archive.

Continue reading