0

I implemented some custom classes to reflect database models and now I want to add some helper properties that can be called when filling a collectionView.

this is the class:

class MyClass {
    var id:String!
    var createDate: NSDate!
    //etc.....


    //iOS Helper Variables for collectionView rendering
    var myCelltype:CellType!

    enum CellType {
        case Text
        case Image
        case Video
    } 
}

later in the view controller I want to decide what cell type to use depending on this enum, so I built a switch case like this

var myType = collection[indexPath.item].myCelltype
//I can see Text/Image/Video correctly being set by another Method when having a breakpoint here


switch myType {

case .Text:
    println("Cell Type: Text")

case .Image:
    println("Cell Type: Single Image")

case .Video:
    println("Cell Type: Video")

default:
    println("Cant get cell type")
    break  
}

here I get

Enum case 'Image' not found in type 'MyClass.CellType!' //same error for Text/Video

Should I rather be using some default value initializer and then overwrite it when creating objects of this type or did I misunderstand something else about enums?

longbow
  • 1,593
  • 1
  • 16
  • 39

0 Answers0