Numero Uno Software Store - stuck mutating func upgrade, how to increase value

Hi All,

I am stuck at step 7 of the Numero Uno Software Store exercise, adding the mutating function.

“Let’s create a mutating method upgrade() that sets its own value one step higher unless it is the highest edition, in which case it should print Can’t upgrade further to the console. For example, if an instance of Edition is set to the basic case, upgrade() should set the instance to case premium”.

This is what I got but I can not get the mutating fund upgrade to work:

enum Edition: String {
  case basic 
  case premium 
  case ultimate 

  mutating func upgrade() {
    if Edition.self != ultimate {
      self.rawvalue + 1 
    } else {
      print("Can’t upgrade further")
    }
    }
  }

I am getting the following errors:

NumeroUno.swift:23:24: error: enum case 'ultimate' cannot be used as an instance member
    if Edition.self != ultimate {
                       ^~~~~~~~
                       Edition.
NumeroUno.swift:24:12: error: value of type 'Edition' has no member 'rawvalue'
      self.rawvalue + 1 
      ~~~~ ^~~~~~~~

Thanks for your help.

I know this is a late response but maybe someone else will have the same question as you.

enum Edition: String {
  case basic, premium, ultimate

  mutating func upgrade() {
    switch self {
      case .basic:
        self = .premium
      case .premium:
        self = .ultimate
      case .ultimate:
        print("Can't upgrade further")
    }
  }
}
2 Likes