title: Update an object on core data swift 4
body: <p>I have several items of jobs in core data entity whose jobId is -1. I need to fetch all those items and update jobId by proper ids which are in my object that is passed in updateMyJobs method. I haven't extracted NSManagedObject class to work on core data (i.e.- I've checked the entity as Class definition)</p>
  
  <p>Here's my code:</p>
  
  <pre><code>func updateMyJobs(jobId: Int){
      managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
      let fetchRequest = NSFetchRequest&lt;NSFetchRequestResult&gt;(entityName: "DBJobsNearBy")
      fetchRequest.predicate = NSPredicate(format: "jobId = '-1'")
      let result = try? managedObjectContext.fetch(fetchRequest)
      let resultData = result as! [DBJobsNearBy]
      for object in resultData {
          print(object.jobId)
          if object.jobId == -1 {
              object.setValue("\(jobId)", forKey: "jobId")
          }
      }
      do {
          try managedObjectContext.save()
          print("saved!")
      } catch let error as NSError  {
          print("Could not save \(error), \(error.userInfo)")
      }
  }
  </code></pre>
  
  <p>I passed some integer value and call the above method to update the item like this.</p>
  
  <pre><code>DatabaseHandler.shared.updateMyJobs(jobId: 222)
  </code></pre>
  
  <p><strong>Error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for attribute: property = "jobId"; desired type = NSNumber; given type = Swift._NSContiguousString; value = 222.'</strong></p>
  
  <p>I'm trying to set new jobId to the related object in core data entity. Is it necessary to extract NSManagedObject Class or not. Please someone help me to do this. Thank You.</p>