Xcode
enum
Swift
struct
Swift3.0
More than 1 year has passed since last update.

内部の変数を渡す場合

import UIKit

enum Fruit: CustomStringConvertible {

    case apple
    case banana

    static var appleValue: String = "りんご"
    static var bananaValue: String = "バナナ"

    var description: String {
        switch self {
        case .apple:
            return Fruit.appleValue
        case .banana:
            return Fruit.bananaValue
        }
    }

}

print(Fruit.apple)
print(Fruit.banana)

りんご
バナナ

外部から変数を書き換えたい場合

import UIKit

var aapple = "りんご"
var bbanana = "バナナ"

enum Fruit: CustomStringConvertible {

    case apple
    case banana

    static var appleValue: String = aapple
    static var bananaValue: String = bbanana

    var description: String {
        switch self {
        case .apple:
            return Fruit.appleValue
        case .banana:
            return Fruit.bananaValue
        }
    }

}

print(Fruit.apple)
print(Fruit.banana)

りんご
バナナ