Matrosov Alexander Matrosov Alexander - 1 year ago 110
Swift Question

Swift how to use enum to get string value

I have enum:

enum NewProgramDetails: String {
case Description = "Description", ToMode = "To Mode", From = "From", To = "To", Days = "Days"

static let allValues = [Description, ToMode, From, To, Days]

I want to use this enum to display in my cell depend on indexPath:

cell.textLabel.text = NewProgramDetails.ToMode

error: Cannot assign value of type 'ViewController.NewProgramDetails' to type 'String?'

How can I use enum values to assign it to label text as a string?

Answer Source

Use the rawValue of the enum:

cell.textLabel.text = NewProgramDetails.ToMode.rawValue
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download