<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">I’m writing a summary of Swift functions in my iTunes U course. I just wanted to clear a few things as I can find no definitive information online to formally back up what I say.</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">&nbsp;</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">In my summary, I say something along these lines:</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">&nbsp;</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt 36pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">“A reference to a function can be likened to a reference to a data structure, and in many ways is similar to an instance of a class. There is immutable program code, and state, some of which might be mutable. Therefore, in a multithreaded environment, you need to treat any function that captures and mutates data in the same way as shared mutable state in order to avoid creating race conditions”</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">&nbsp;</span></p><p class="MsoListParagraph" style="text-indent: 0px; margin: 0cm 0cm 0.0001pt 36pt;"><span style="background-color: rgba(255, 255, 255, 0);"><span lang="EN-GB">·<span style="line-height: normal;">&nbsp;&nbsp;&nbsp;</span></span><span lang="EN-GB">Is there a description of how a Swift function type is structured in memory?&nbsp;</span></span></p><p class="MsoListParagraph" style="text-indent: 0px; margin: 0cm 0cm 0.0001pt 36pt;"><span style="background-color: rgba(255, 255, 255, 0);"><span lang="EN-GB">·<span style="line-height: normal;">&nbsp;&nbsp;&nbsp;</span></span><span lang="EN-GB">Is it ‘reasonable’ to liken a function to a class instance in this way? (given this is only supposed to be an analogy).&nbsp;</span></span></p><p class="MsoListParagraph" style="text-indent: 0px; margin: 0cm 0cm 0.0001pt 36pt;"><span style="background-color: rgba(255, 255, 255, 0);"><span lang="EN-GB">·<span style="line-height: normal;">&nbsp;&nbsp;&nbsp;</span></span><span lang="EN-GB">Do I assume correctly about the dangers of capturing data in multithreaded code?</span></span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">&nbsp;</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">Cheers</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">&nbsp;</span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt;"><span lang="EN-GB" style="background-color: rgba(255, 255, 255, 0);">Nick</span></p></div></body></html>