Legacy Constructor
ID |
swift.legacy_constructor |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Swift |
Tags |
code-smell, modernisation |
Description
Reports use of legacy C-style geometry / range factory functions in favour of Swift’s named-argument initialisers.
CGRectMake(0, 0, 10, 10) // FLAW
CGSizeMake(10, 20) // FLAW
NSMakeRange(0, 5) // FLAW
CGRect(x: 0, y: 0, width: 10, height: 10) // OK
CGSize(width: 10, height: 20) // OK
NSRange(location: 0, length: 5) // OK
Rationale
Named-argument initialisers self-document the call: there’s no positional ambiguity about which number means "width" versus "x". They are also the canonical form in modern iOS / macOS SDK headers.