Matrosov Alexander Matrosov Alexander - 2 months ago 9x
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?


Use the rawValue of the enum:

cell.textLabel.text = NewProgramDetails.ToMode.rawValue