I am kind of new to Swift/Xcode and currently building my first app. I am using CoreData to persist some objects. I would like to rename my .xcdatamodeld file but after doing so my app crashes immediately after running it in simulator with the following error message:
CoreData: error: Failed to load model named SnapShot Swift/UnsafeRawBufferPointer.swift:1137: Fatal error: UnsafeRawBufferPointer with negative count
When reverting the changes everything works fine again. I guess I have to adjust some references in my project but I don't know which and my research on the internet did not bring me any further which is why I am asking here now. I am using Xcode 15.1 if that is somehow important. I cleaned and rebuilt the project and also tried to search for any occurrences of the old name in the project with Xcode's search funtion but got no matches. Thank you for your help :)
The same question have been asked earlier also, if you see this post -- Rename xcdatamodel file
But I was doing this on a fresh project and I didn't found any crash. There are two observations
NSPersistentContainer(name: "New_updated_name")here. But it will create a new core data file and all your data that have been saved on earlier file will not migrate into the new one.What I have tried --
In the attached sample project first set the .xcdatamodeld as FirstModel e.g and then save some names in it,
Then rename the .xcdatamodeld and try to print the values, you will not get the data saved earlier.
Then again update the .xcdatamodeld to it's original name then you will get the data.
DatabaseManager.swift
Student+CoreData.swift
Student+CoreDataProperties.swift
ViewController.swift
ModelObject