Skip to content

Enumerations

Along with being able to identify unused enumerations, Periphery can also identify individual unused enum cases. Plain enums that are not raw representable, i.e., that don’t have a String, Character, Int, or floating-point value type, can be reliably identified. However, enumerations that do have a raw value type can be dynamic, and therefore must be assumed to be used.

enum MyEnum: String {
case myCase
}
func someFunction(value: String) {
if let myEnum = MyEnum(rawValue: value) {
somethingImportant(myEnum)
}
}

There’s no direct reference to the myCase case, so it’s reasonable to expect it might no longer be needed. However, if it were removed, we can see that somethingImportant would never be called if someFunction were passed the value of "myCase".