Legacy Constant
ID |
swift.legacy_constant |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Swift |
Tags |
code-smell, modernisation |
Description
Reports references to legacy C-style global constants imported from Foundation / CoreGraphics that have struct-scoped Swift equivalents.
M_PI // FLAW — use Double.pi
CGFLOAT_MIN // FLAW — use CGFloat.leastNormalMagnitude
CGFLOAT_MAX // FLAW — use CGFloat.greatestFiniteMagnitude
DBL_MAX // FLAW — use Double.greatestFiniteMagnitude
Double.pi // OK
CGFloat.leastNormalMagnitude // OK
Rationale
The Swift constants are:
-
Type-scoped — autocompletion works, the type is unambiguous.
-
Documented in Swift API reference, not buried in C headers.
-
Consistent across platforms.
The legacy macros only exist because the Foundation / CoreGraphics modules expose the C symbols for ObjC compatibility.