Maybe I'm over thinking this or having a brain cramp.
typealias myZero = reallyLongAndObfuscatedEnum.ZERO
Let's say I have some legacy code and need to convert it to Swift 3. This is of course a very simplified version of what I'm dealing with.
enum reallyLongAndObfuscatedEnum {
///zero
struct ZERO {
static let float_t:Float32 = Float32(0)
static let double_t:Float64 = Float64(0)
static let cgfloat_t:CGFloat = CGFloat(0)
static let desc:String = "/* nothingness, nada, it is the void */"
}
}
Now instead of typing:
ReallyLongEquation * reallyLongAndObfuscatedEnum.ZERO.cgfloat_t
I can use:
ReallyLongEquation * myZero.cgfloat_t
Is typealias the "Swift" way to do this?
If all you are looking for is an alternative (and shorter) name for
reallyLongAndObfuscatedEnum.ZERO, then yestypealiaswould be the way to go.At the risk of leading you down the wrong path (since I don't have the full context), you may also want to look at Associated Values in Swift enums. For instance you could rewrite the enum as