iosswiftcore-datamagicalrecord

Saving NSManagedObject via MagicalRecord does not work


I have create an object:

let exercise = ExerciseEntity.mr_createEntity()

func updateLocalExercise(with exercise: ExerciseEntity, completion: @escaping (ResultInfo<[ExerciseEntity]>) -> Void) {

                MagicalRecord.save({ (context) in

if let localExercise = exercise.mr_(context) { this actually nil and throws some error in log
}

}

My question is how to save ExerciseEntity.mr_createEntity correctly


Solution

  • Call MR_saveToPersistentStoreAndWait to save data. Check all save methods in NSManagedObjectContext (MagicalSaves) class.

    You should use MR_createEntityInContext instead of MR_createEntity. MR_createEntity is deprecated.