我正在尝试将对象数组保存到另一个实体的实体“多对多”关系中(不确定如何解释)。我发誓这段代码以前是可以工作的,但是它突然停了下来,我不确定为什么为什么我没有更改任何与之相关的代码,我都记得。我收到一个SIGABRT错误,该错误“终止于NSException类型的未捕获异常”。任何输入都将有所帮助。
func save (completion: (_ finished: Bool) -> ()){
guard let managedContext = appDelegate?.persistentContainer.viewContext else { return }
let workout = Workout(context: managedContext)
workout.nameOfWorkout = workoutNameLabel.text!
workout.exercises = NSSet(array: exercises) // problem exists on this line
workout.numberOfExercises = Int32(exercises.count)
print("\(workout.exercises!.count)")
print ("\(workout.exercises!)")
do{
try managedContext.save()
completion(true)
} catch {
debugPrint("error: \(error.localizedDescription)")
completion(false)
}
}