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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to