Legacy CGGeometry Functions
ID |
swift.legacy_cggeometry |
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 accessor functions for CGRect (and friends) in
favour of Swift’s struct-scoped properties.
CGRectGetMinX(r) // FLAW — use r.minX
CGRectGetWidth(r) // FLAW — use r.width
CGRectGetMidY(r) // FLAW — use r.midY
r.minX // OK
r.width // OK
Rationale
The struct-scoped properties are auto-completable, type-safe, and read more naturally as method-call-chained expressions. The C-style accessors are kept around only for ObjC source-compatibility.
Remediation
Replace each accessor with the corresponding struct member:
let x = r.minX // CGRectGetMinX(r)
let y = r.minY // CGRectGetMinY(r)
let w = r.width // CGRectGetWidth(r)
let h = r.height // CGRectGetHeight(r)
let cx = r.midX // CGRectGetMidX(r)