<HTML><BODY><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;">Assume we have this code:</p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;">Immediately two Timer's closures captured two copy of initial values of instance Test, with internal num values is 0.</p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;">&nbsp;<br></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #008400;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #008400;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">//: Playground - noun: a place where people can play</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">import</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> UIKit</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #d12f1b;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #d12f1b;"><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">var</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #000000;"> str = </span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">"Hello, playground"</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">struct</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> Test {</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">var</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> num = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #272ad8;">0</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">mutating</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">func</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> newNum(new: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #703daa;">Int</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">) {</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">num</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> = new</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; }</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">}</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">var</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;"> test = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">Test</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">()</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #703daa;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #703daa;">Timer</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;">scheduledTimer</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">(withTimeInterval: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #272ad8;">1.0</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">, repeats: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">false</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">) { (timer) </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">in</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;">print</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #d12f1b;">"tick"</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">)</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">test</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #31595d;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #31595d;">newNum</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">(new: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #272ad8;">8</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">)</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">}</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #703daa;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #703daa;">Timer</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;">scheduledTimer</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">(withTimeInterval: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #272ad8;">2.0</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">, repeats: </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">false</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">) { (timer) </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #ba2da2;">in</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #d12f1b;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #d12f1b;"><span style="font-variant-ligatures: no-common-ligatures; color: #000000;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #000000;">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #3e1e81;">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #000000;">(</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">"tack, test.num = </span><span style="font-variant-ligatures: no-common-ligatures; color: #000000;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #000000;">\</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">test</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #000000;">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #4f8187;">num</span><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">)"</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #000000;">)</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">}</span></p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #3e1e81;" data-mce-style="margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: #3e1e81;"><span style="font-variant-ligatures: no-common-ligatures;" data-mce-style="font-variant-ligatures: no-common-ligatures;">CFRunLoopRun</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000;" data-mce-style="font-variant-ligatures: no-common-ligatures; color: #000000;">()</span></p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;"><br><br><br></p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;">We have next log:</p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;"><strong>tick</strong></p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;"><strong>tack, test.num = 8</strong></p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545; min-height: 14px;">&nbsp;</p><p style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;" data-mce-style="margin-bottom: 0px; font-size: 12px; line-height: normal; font-family: 'Helvetica Neue'; color: #454545;">Why Timer's two closure return to us value 8 and not 0?</p><br><br><br>-- <br>Седых Александр</BODY></HTML>