FabricioG
FabricioG

Reputation: 3310

Use of undeclared type in App development with swift

I'm trying to learn Swift and I am reading through App. development with swift. In chapter two it uses this as an example to show how Struct works...

struct Shirt {
    var size: Size
    var color: Color
}

let myShirt = Shirt(size: .xl, color: .blue)

When I run it in playground I get an error "Swift Compiler Error" Use of undeclared type 'Size" and same for "color". I'm wondering why it doesn't work if its' in the book?

Upvotes: 0

Views: 443

Answers (1)

toddg
toddg

Reputation: 2906

As @rmaddy mentioned in the comments you will need to declare the enums for Size and Color. Try something like this:

enum Color {
    case Blue
}

enum Size {
    case xl
}

struct Shirt {
    var size: Size
    var color: Color
}

let myShirt = Shirt(size: .xl, color: .blue)

Upvotes: 0

Related Questions