title: Cannot find 'weak' in scope iOS swift
body: <p>i am trying to avoid memory leak using clousures in swift , but swift is not recognising the [weak self] inside the closure.</p>
  <pre><code>  //  class :
      
      class LanguageClass {
          
          var languageClosure : (() -&gt; ())?
          var name : String = &quot;&quot;
          
          init() {
              self.languageClosure = { [weak self]
                  print(&quot;\(self.name) is the language&quot;)
              }
          }
          deinit {
              print(&quot;deinitialized&quot;)
          }
          
      }
      
     // consumption :
  
        var swiftLanguage : LanguageClass? = LanguageClass()
        swiftLanguage?.name = &quot;Swift&quot;
        swiftLanguage?.languageClosure?()
        swiftLanguage = nil
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Z610O.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Z610O.png" alt="closure and class" /></a></p>