<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 22, 2016, at 7:38 PM, Ricardo Parada &lt;<a href="mailto:rparada@mac.com" class="">rparada@mac.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Joe,<div class=""><br class=""></div><div class="">I have a few of questions after reading your proposal.</div><div class=""><br class=""></div><div class=""><b class="">Question #1 :&nbsp;</b></div><div class=""><br class=""></div><div class="">Let’s say that the property behavior has an&nbsp;<span style="font-family: Consolas;" class="">init()</span>&nbsp;method as in your example for the <font face="Consolas" class="">lazy</font>&nbsp;property behavior where you simply assign <font face="Consolas" class="">nil</font> to the <font face="Consolas" class="">value</font>. &nbsp;After the declaration of the <font face="Consolas" class="">lazy</font> behavior you show how to use this behavior for a variable declared in the global scope, It appears to me that the <font face="Consolas" class="">init()</font> gets called at the time the property is declared because you mention in the comment that the property is inited to <font face="Consolas" class="">nil</font>:</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> [<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">lazy</span>] x <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">1738</span> <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// Allocates an Int? behind the scenes, inited to nil</span>
</pre></div><div class=""><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);"><br class=""></span></div><div class="">My question is as follows: What about when the property is declared inside a class? &nbsp;At what point is the <font face="Consolas" class="">init()</font> called?</div></div></div></blockquote><div><br class=""></div><div>The init() is called at the beginning of initialization, as if the behavior's storage were expanded out with an initial value:</div><div><br class=""></div><div>class Foo {</div><div>&nbsp; var [lazy] x = 1738</div><div><br class=""></div><div>&nbsp; // Compiler expands this behind the scenes:</div></div><div><div>&nbsp; var `x.[lazy]`: Int? = lazy.init()</div></div><div>}</div><div><br class=""></div><div>It's useful for this to happen later, since many behaviors would want to allow out-of-line initialization in the containing type's init method:</div><div><br class=""></div><div>class Bar {</div><div>&nbsp; var [runcible] x: Int</div><div><br class=""></div><div>&nbsp; init() {</div><div>&nbsp; &nbsp; x = 679 // Would like runcible.init(679) to trigger here</div><div>&nbsp; }</div><div>}</div><div><br class=""></div><div>There are some subtleties to this, so I wanted to subset that out as a separate extension.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><b class="">Question #2 :</b></div><div class=""><br class=""></div><div class="">In your example for the <font face="Consolas" class="">synchronized</font> property behavior, you have the following line of code in the declaration of the behavior:</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51);" class="">  <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> value: Value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> initialValue
</pre></div><div class=""><br class=""></div><div class="">The <font face="Consolas" class="">get</font> and the <font face="Consolas" class="">set</font> accessors use <font face="Consolas" class="">withLock { … }</font> to get / set the <font face="Consolas" class="">value</font>. &nbsp;However, the code above that stores the <font face="Consolas" class="">initialValue</font> in the <font face="Consolas" class="">value</font> variable does not use <font face="Consolas" class="">withLock { … }</font>. &nbsp;Does it matter? &nbsp;And similar to question #1, at what time is this code executed?</div></div></div></blockquote><div><br class=""></div><div>The initializer will occur at the start of the container's initialization, as in the previous example (though `synchronized` is really somewhere you want to be able to trigger the initialization out-of-line). For `synchronized`, it's unlikely to be necessary to synchronize the initialization, since a class in Swift can't be shared across threads until it's already fully initialized.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><b class=""><br class=""></b></div><div class=""><b class="">Comments About this Proposal:</b></div><div class=""><br class=""></div><div class="">I’ve been following the threads on property behaviors as it is one of my favorite threads. &nbsp;I don’t always understand everything that you are all saying, for example, I am not sure if I understand what you guys means by out-of-line initialization in this context. &nbsp;</div><div class=""><br class=""></div><div class="">In general, I like the proposal. &nbsp; At first I thought that the square brackets notation could be confusing as it looks like an array. &nbsp;I understand there aren’t many options to use. &nbsp;However, now that I think of this as a list of property behaviors preceding the property name, I think the square brackets are the right choice. &nbsp;</div></div></div></blockquote><br class=""></div><div>Thanks! Don't be afraid to ask questions about things that aren't clear. When I refer to out-of-line initialization, I refer to the ability to initialize properties after their initial declaration. For local properties, this is possible by assigning the initial value to the property after its immediate declaration:</div><div><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div>func foo() {</div><div>&nbsp; var x: Int</div><div>&nbsp; // some other stuff happens that doesn't use x</div><div>&nbsp; x = 22 // out-of-line initialization of x</div><div>}</div></blockquote><div class=""><br class=""></div><div class="">and for properties inside classes, this is possible during the class's `init` implementations:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">class Foo {</div><div class="">&nbsp; var x: Int</div><div class=""><br class=""></div><div class="">&nbsp; init(x: Int) {</div><div class="">&nbsp; &nbsp; self.x = x // out-of-line initialization of self.x</div><div class="">&nbsp; }</div><div class="">}</div></blockquote><br class=""><div class="">-Joe</div></body></html>