Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

ios - Update / change the rawValue of a enum in Swift

Taking the below enum for instance

enum Name : String {

  case Me = "Prakash"
  case You = "Raman"

}

Can I do the following

Change the raw value of one "case" to something else.

Name.Me = "Prak"

Add a new case to the ENUM

Name.Last = "Benjamin"

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Short answer: No, you can't.

Enumeration types are evaluated at compile time.
It's not possible to change raw values nor to add cases at runtime.

The only dynamic behavior is using associated values.

Reference: Swift Language Guide: Enumerations


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...