title: Writing a Custom Setter for my Variable - Swift
body: <p>I am trying to run a Setter on a property when it changes, that will then also affect the logic in that class:</p>
  
  <p>Here is how it used to look in Objective - C:</p>
  
  <pre><code>@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
  </code></pre>
  
  <p><em>Set Method for fetchedResultsController:</em></p>
  
  <pre><code>- (void)setFetchedResultsController:(NSFetchedResultsController *)newFetchResultsContrller
  {
      NSFetchedResultsController *oldfetchResultsController = _fetchedResultsController;
      if (newFetchResultsContrller != oldfetchResultsController) {
          _fetchedResultsController = newFetchResultsContrller;
          newFetchResultsContrller.delegate = self;
          if ((!self.title || [self.title isEqualToString:oldfetchResultsController.fetchRequest.entity.name]) &amp;&amp; (!self.navigationController || !self.navigationItem.title)) {
              self.title = newFetchResultsContrller.fetchRequest.entity.name;
          }
          if (newFetchResultsContrller) {
  
              [self performFetch];
          } else {
  
              [self.tableView reloadData];
          }
      }
  }
  </code></pre>
  
  <p>Here is my attempt in Swift. However I cannot get the newFetchResultsController, thus cannot complete rest. Is this the right way of setting a property in swift ? How can I do the same principle as above shown in Objective C in Swift?</p>
  
  <pre><code>var fetchedResultsController:NSFetchedResultsController! {
      willSet {
          println("Set fetchedResultsController Called")
          self.fetchedResultsController.delegate = self
          performFetch()
      }
  }
  </code></pre>