[swift-users] Swift functions and captured mutable data

Nicholas Outram nicholas.outram at icloud.com
Wed Jul 27 12:12:51 CDT 2016


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.
 
In my summary, I say something along these lines:
 
“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”
 
·   Is there a description of how a Swift function type is structured in memory? 
·   Is it ‘reasonable’ to liken a function to a class instance in this way? (given this is only supposed to be an analogy). 
·   Do I assume correctly about the dangers of capturing data in multithreaded code?
 
Cheers
 
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160727/da6a2b3f/attachment.html>


More information about the swift-users mailing list