[swift-users] Clarification about the Swift API Design Guide - Initializer and factory methods calls
Kelvin Ma
kelvin13ma at gmail.com
Tue Jan 9 14:10:52 CST 2018
I didn’t write the guidelines but i never really felt
Array(repeating:count:) was weird, you have two arguments, they need to be
distinguished, and repeating is actually shorter than repeatedValue.
On Tue, Jan 9, 2018 at 12:09 PM, Gaétan Zanella via swift-users <
swift-users at swift.org> wrote:
> Swift API Design Guide
> <https://swift.org/documentation/api-design-guidelines> 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 UIKit, the Swift Standard Library or in Foundation, we find code
> like :
>
> struct Array<T> {
> // ...
> init(repeating repeatedValue: Array.Element, count: Int)
> }
>
> struct Data {
> // ...
> init(referencing reference: NSData)
> }
>
> class UIImage {
> // …
> init?(named name: String, in bundle: Bundle?, compatibleWith
> traitCollection: UITraitCollection?)
> }
>
> I understand that some UIKit methods inherit their ObjC declarations like
> imageNamed:inBundle:compatibleWithTraitCollection:
> <https://developer.apple.com/documentation/uikit/uiimage/1624154-imagenamed?language=objc>
> .
> But what about Foundation and the Swift Standard Library ?
>
> I agree that the initializers respect the Swift fundamentals : clean,
> short, readable, and consistent.
> But the guide seems to be clear about it : we should not write such things.
>
> Could someone shed some light on this point for me ? The subtlety about it.
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20180109/49db90ca/attachment.html>
More information about the swift-users
mailing list