3

Swift API Design Guide says:

The first argument to initializer and factory methods calls should not form a phrase starting with the base name

Specially, it advises us against writing things like:

let foreground = Color(havingRGBValuesRed: 32, green: 64, andBlue: 128)
let newPart = factory.makeWidget(havingGearCount: 42, andSpindleCount: 14)
let ref = Link(to: destination)

But in the Swift Standard Library or UIKit we find code like:

struc Array<T> {
    // ...

    init(repeating repeatedValue: Array.Element, count: Int)
}    

class UIImage {
   // ...

   init?(
        named name: String, 
        in bundle: Bundle?, 
        compatibleWith traitCollection: UITraitCollection?
    )
}

Is it correct?

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
GaétanZ
  • 4,870
  • 1
  • 23
  • 30

0 Answers0