无法将数组保存到实体(核心数据)

时间:2019-01-27 07:13:20

标签: swift core-data entity-relationship

我正在尝试将对象数组保存到另一个实体的实体“多对多”关系中(不确定如何解释)。我发誓这段代码以前是可以工作的,但是它突然停了下来,我不确定为什么为什么我没有更改任何与之相关的代码,我都记得。我收到一个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)
    }
}

0 个答案:

没有答案
相关问题