The user in my app can create multiple “Song” entities and add to a playlist in the range of 10k to 100k.
I don’t think I can use NSBatchInsertRequest to save them until they press “Done” since that will save them permanently to disk straight away.
I want the user to have the option to rollback to their previous state of their playlist by pressing on “Cancel” button.
How do I handle this situation?
func savePlaylist() {
let newPlaylist = Playlist(context: moc)
newPlaylist.name = "Test 1"
newPlaylist.id = UUID()
var array: [Any] = []
for i in 0...100000 {
let song = Song(context: moc)
song.name = "Song" + "(i)"
song.fileExtension = "mp3"
song.artist = "Some artist"
array.append(song1)
}
newPlaylist.songs = NSOrderedSet(array: array)
try? moc.save()
}