title: How to create a dictionary of weak references in Swift?
body: <p>I need to store delegates which are views in a dictionary. Now I want to hold them as weak references, So if the user quits the screen my dictionary won't be the one preventing those views to cleanup.</p>
  
  <p>I was trying to use the solution from:</p>
  
  <p><a href="https://stackoverflow.com/questions/24127587/how-do-i-declare-an-array-of-weak-references-in-swift">How do I declare an array of weak references in Swift?</a></p>
  
  <p>But for some reason as soon as I add the line of code where I try to get the real delegate from the weak object:</p>
  
  <pre><code>if let realDelegate = delegate.value {
      realDelegate.updateProgressBar(Int(progress * 100), aTaskIndentifier: downloadTask.taskIdentifier)
  }
  </code></pre>
  
  <p>I get the following error in Xcode at compile time:</p>
  
  <blockquote>
    <p>Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1</p>
  </blockquote>
  
  <p>Do you know what is the problem with this solution? Or maybe you could provide another solutions for this task?</p>