Prefer Zero Over Explicit Init

Prefer .zero over explicit init with zero parameters (e.g. CGPoint(x: 0, y: 0))

  • Identifier: prefer_zero_over_explicit_init
  • Enabled by default: No
  • Supports autocorrection: Yes
  • Kind: idiomatic
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning

Non Triggering Examples

CGRect(x: 0, y: 0, width: 0, height: 1)
CGPoint(x: 0, y: -1)
CGSize(width: 2, height: 4)
CGVector(dx: -5, dy: 0)
UIEdgeInsets(top: 0, left: 1, bottom: 0, right: 1)

Triggering Examples

CGPoint(x: 0, y: 0)
CGPoint(x: 0.000000, y: 0)
CGPoint(x: 0.000000, y: 0.000)
CGRect(x: 0, y: 0, width: 0, height: 0)
CGSize(width: 0, height: 0)
CGVector(dx: 0, dy: 0)
UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)