[swift-evolution] [Pitch] Unify preset static "initializers"
Charlie Monroe
charlie at charliemonroe.net
Fri Jun 3 11:07:16 CDT 2016
CGRect.zero should IMHO be deprecated in favor of CGRect() instead, which makes it shorter and more "Swifty". But that's probably just my personal opinion and a bit off topic.
Nevertheless .zero on CGRect is a Swift extension which is `static var`. There is currently no way to have static vars on classes in ObjC, which is where .black() comes from, so it's currently a class method.
On the other hand, you are correct that it's a bit inconsistent, since when you have `static var sharedInstance` on a Swift class, it gets indeed exported into ObjC as +(Instance *)sharedInstance; - so making it the other way around would make sense.
Theoretically, it could be possible to allow annotations, such as NS_SWIFT_NAME(black) to make it a static var:
+(instancetype)blackColor NS_SWIFT_NAME(black);
> On Jun 3, 2016, at 4:48 PM, Bas Broek via swift-evolution <swift-evolution at swift.org> wrote:
>
> Hi all,
>
> I was wondering the other day why "static initializers", as I will call them, are not unified:
>
>> CGRect.zero
> vs
>> UIColor.blackColor() - which will be UIColor.black() in Swift 3.
>
> ... which both do pretty much the same; they are used as convenience initialization for the specific type. I think their intent will be clearer though, when all of them either become static vars (as with CGRect.zero) or static funcs (as with UIColor.black()).
>
> I, though, am not sure which would be the best option.
>
> So I'd like to ask you all two questions:
>
> - Do you think these should be unified? Why (not)?
> - If yes, should funcs or vars be used?
>
> Thanks,
>
> Bas
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list