0

basically, what I wish to do would be

enum MyEnum : MyObject {

case first = MyObject(value1, value2, value3)
...

}

I've looked the documentation and tried to code something like that but it looks like it's not possible as the rawvalue type is complex.

My questions are: so is this complex type of enum can be done? If not, which design would you recommend to do that (as I would like to avoid making huge switch cases)?

Thanks a lot!

lorenzo
  • 1,487
  • 1
  • 17
  • 25
  • I assume that what are you looking for is similar to [this answer](https://stackoverflow.com/questions/41922097/enum-of-structs-in-swift-3-0/41922262#41922262). – Ahmad F Mar 09 '17 at 10:43

1 Answers1

0

Here is an example of achieving this

enum CroudInfo: String {
    case bitkom = "Битком"
    case free = "Свободно"
    case avarage = "Загружено"

    func values() -> (title: String, image: UIImage, textColor: UIColor, fullImage: UIImage) {
        switch self {
        case .bitkom:
            return (self.rawValue, UIImage(named: "redValue")!, UIColor(red: 208 / 255, green: 19 / 255, blue: 0 / 255, alpha: 1), UIImage(named: "redImage")!)
        case .free:
            return (self.rawValue, UIImage(named: "greenValue")!, UIColor(red: 84 / 255, green: 175 / 255, blue: 98 / 255, alpha: 1), UIImage(named: "greenImage")!)
        case .avarage:
            return (self.rawValue, UIImage(named: "yellowValue")!, UIColor(red: 247 / 255, green: 157 / 255, blue: 0 / 255, alpha: 1), UIImage(named: "yellowImage")!)
        }
    }
}
JuicyFruit
  • 2,638
  • 2
  • 18
  • 35