title: Swift: Could not cast value of type Swift.Int16 to Swift.AnyObject
body: <p>Getting the error message  'Could not cast value of type Swift.Int16  to Swift.AnyObject' when I run the line of code below. The error occurs on the line:</p>
  
  <p>'newWorkout.setValue(totalTimeConverted as! AnyObject, forKey: "workoutTime")'</p>
  
  <p>Workout is the name of my entity. It has two attributes; </p>
  
  <ul>
  <li><p>workoutDate of type NSDate </p></li>
  <li><p>workoutTime of type Int16.</p>
  
  <pre><code>let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
  let context: NSManagedObjectContext = appDel.managedObjectContext
  
  
  let newWorkout = NSEntityDescription.insertNewObjectForEntityForName("Workout", inManagedObjectContext: context) as! Workout
  
  let totalTimeConverted = Int16(totalTime)
  
  // Add parameters
  newWorkout.setValue(totalTimeConverted as! AnyObject, forKey: "workoutTime")
  newWorkout.setValue(NSDate(), forKey: "workoutDate")
  
  
  do {
      try context.save()
  } catch {
      print("Error saving data")
  }
  
  
  do {
      let request = NSFetchRequest(entityName: "Workout")
      let results = try context.executeFetchRequest(request)
      if results.count &gt; 0 {
  
      for item in results as! [NSManagedObject]{
  
          let time = item.valueForKey("workoutTime")
          let workoutDate = item.valueForKey("workoutDate")
          print(time!, workoutDate!)
  
      }
      }
  } catch{
      print("Error loading data")
  }
  </code></pre></li>
  </ul>