Friday, October 16, 2015

[Swift] Duplicate values in enum

Swift doesn't support duplicated values (aliases):

enum WebColor : UInt
{
    case Cyan = 0x00FFFF
    case Aqua = 0x00FFFF // This line generates error "Raw value of enum case is not unique"

    ...
}

Here is a simple workaround:

enum WebColor : UInt
{
    case Cyan = 0x00FFFF
    static var Aqua: UInt { get { return 0x00FFFF } } // duplicate with Cyan

    ...
}

No comments:

Post a Comment