title: Swift Closures [unowned singleton]
body: <p>Having an issue with a recursive memory leak in Swift, where a singleton is being called inside the closure of another singleton.</p>
  
  <pre><code>NetworkManager.sharedInstance.doThingWithCompletion(urlString) { [unowned self] (complete) -&gt; Void in
  
         if complete == true {
  
             if self.fetchedResultsController.fetchedObjects?.count &gt; 0 {
  
                 CoreDataManager.sharedInstance.save(self.dictionary, completion: { (complete) -&gt; Void in
  
              })
          }
      }
  }
  </code></pre>
  
  <p>How do I add the singleton as unowned to the capture list? Should I even be doing that??</p>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <p>Spotted by Quantaliinuxite, Core Data Manager had an issue... absolutely no problem with this sort of architecture. </p>
  
  <pre><code>static let sharedInstance = BFSCoreDataManager()
  
  deinit {
  
      NSNotificationCenter.defaultCenter().removeObserver(self)
  }
  
  // MARK: - Saving
  
  func observeContext(context:NSManagedObjectContext) {
  
      NSNotificationCenter.defaultCenter().addObserver(
          self,
          selector:"mergeChangesFromNotification:",
          name: NSManagedObjectContextDidSaveNotification,
          object: nil) // ** PROBLEM WAS HERE **
  }
  
  func mergeChangesFromNotification(notification:NSNotification) {
  
      dispatch_async(dispatch_get_main_queue()) {
  
          self.managedObjectContext.mergeChangesFromContextDidSaveNotification(notification)
      }
  }
  </code></pre>