<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I had the same problem with delegate methods (they all had the same prefix). I used lambda as a workaround, but I agree it is less elegant :<div class=""><br class=""></div>let b: = { Foo(customNumber: $0) }<div class=""></div><div class="">let c: = { Foo(numberToInc: $0) }</div><div class=""><div class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Pierre</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 10 déc. 2015 à 23:41, Austin Zheng via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hello Swift users,<div class=""><br class=""></div><div class="">I have a question about capturing references to initializers. You can do the following right now:</div><div class=""><br class=""></div><div class=""><div class="">struct Foo {</div><div class=""> let number : Int</div><div class=""> // This type has a single initializer</div><div class=""> init() {</div><div class=""> number = 10</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">let a = Foo.init // a's type: () -> Foo</div></div><div class=""><br class=""></div><div class="">So far so good. Now, let's add in a second initializer:</div><div class=""><br class=""></div><div class=""><div class="">extension Foo {</div><div class=""> init(customNumber: Int) {</div><div class=""> number = customNumber</div><div class=""> }</div><div class="">}</div></div><div class=""><br class=""></div><div class="">Now, if you want to capture a reference to one of the initializers, you can annotate the variable with the explicit function type:</div><div class=""><br class=""></div><div class=""><div class="">let a : () -> Foo = Foo.init</div><div class="">let b : Int -> Foo = Foo.init</div></div><div class=""><br class=""></div><div class="">My question involves the case where you have multiple initializers that take the same arguments and types. How would you capture initializers then?</div><div class=""><br class=""></div><div class=""><div class="">extension Foo {</div><div class=""> init(numberToInc: Int) {</div><div class=""> number = numberToInc + 1</div><div class=""> }</div><div class="">}</div></div><div class=""><br class=""></div><div class="">How do I capture a reference to the numberToInc: initializer, versus the customNumber: initializer?</div><div class=""><br class=""></div><div class="">Best regards,</div><div class="">Austin</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ST9LHNQ2kYRKURQJ7G-2FmGCudH8brFLVBGfh-2Becw1t9hd0c2n3SKpIZti-2BBP-2Buy-2FdNsyotUd6dd3YMiu9cQa-2BUqg3MCjtvg04uBbLX9X9aAZyneSl2-2FCd9BHc686hqSkLzr3JagiRvPPxifTz4T5NDtYZz8XFMSx9UwsyHxb5VywsMnPgndegVnr4I7a1tuqeGv0n19TC9JL6d5lIuoD3YcLIC6dLwlO5XJjUXuKQ4xE-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></div></body></html>