user11821601
user11821601

Reputation:

Using enums in Swift

I am new to swift, after programming years with Objective-C.

I declare this on a file

  public enum Identifier {
    case car, boat, toy, water
  }

From another class I do:

var type : Identifier = Identifier.car

ERROR: Use of undeclared Identifier

I also tried

class MyTypes {
  enum Identifier {
    case car, boat, toy, water
  }
}

and then

var type : MyTypes = MyTypes.Identifier.car

How do I use that?

Upvotes: 1

Views: 56

Answers (1)

Rob
Rob

Reputation: 437392

Possible sources of the problem include that the file hasn’t been saved yet or that the file hasn’t been included in your Xcode project’s target. It would appear that the latter issue is the problem here.


By the way, your second example, defined within MyTypes, should be declared as follows:

var type: MyTypes.Identifier = .car

Or as:

var type = MyTypes.Identifier.car

Upvotes: 2

Related Questions