title: unrecognized selector sent to instance with Coredata Swift
body: <p>I keep getting this error whenever I try to update a value of core data model.
  Here is my model </p>
  
  <pre><code>import Foundation
  import CoreData
  
  @objc(Habit)
  class Habit: NSManagedObject {
  
      @NSManaged var name: String
      @NSManaged var trackingType: NSNumber
  }
  </code></pre>
  
  <p>Here is my code tableViewCell</p>
  
  <pre><code>override func setSelected(selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
          if selected {
              self.accessoryType = UITableViewCellAccessoryType.Checkmark
              if self.habit? != nil {
                  self.habit?.trackingType = index
  
              }
  
          } else {
              self.accessoryType = UITableViewCellAccessoryType.None
          }
          // Configure the view for the selected state
  
      }
  </code></pre>
  
  <p>I keep getting error <strong>"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Habit setTrackingType:]: unrecognized selector sent to instance 0x7fdcbb002c90'"</strong></p>
  
  <p>at line 
  self.habit?.trackingType = index</p>
  
  <p>I am struggling to fix this for last 2 days.</p>
  
  <p>Edit:</p>
  
  <p>The model habit is initialized in below way</p>
  
  <pre><code>func getHabits() -&gt; [AnyObject]{
          let entityDescription =
          NSEntityDescription.entityForName("Habit",
              inManagedObjectContext: managedObjectContext!)
  
          let request = NSFetchRequest()
          request.entity = entityDescription
  //        
  //        let pred = NSPredicate(format: "(trackingType != -1)")
  //        request.predicate = pred
  
          var error: NSError?
  
          var objects = managedObjectContext?.executeFetchRequest(request,
              error: &amp;error)
  
          return objects!;
      }
  </code></pre>
  
  <p>The returned list is used everywhere in the app. Basically I fetch and item from the list and update its attributes and then save it again</p>