[swift-evolution] Global init() functions

Jean-Daniel dev at xenonium.com
Sat Nov 19 11:27:22 CST 2016


> Le 19 nov. 2016 à 15:58, Alan Cabrera via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> I’m not sure if this was proposed or not; or even if this is a Swift-ly way of doing things.  It would be pretty handy to be able to declare init() functions in my module to register handlers.  It’s a common pattern in enterprise software.
> 
> Currently, I have to generate a lot of boilerplate code to emulate the behavior.  I think it would be cleaner to have these global init() functions.
> 

I’d rather like a swift attribute equivalent to : __attribute__((constructor))

It will not force me to call my initializer init, and moreover it will let me declare multiple functions so I would be able to register multiples handlers from a single module without having to group all the register call into a single init() function.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161119/180c60ff/attachment.html>


More information about the swift-evolution mailing list