Temporary Objects with CoreData


I have an app that uses CoreData. It tracks some live player stats that the user inputs during a game. These stats are attached to the player object and then saved to an intermediate once a game is completed.


You can also look at old games and see those stats using the same screen that tracks live games.

My problem is that a game can be going on and these player objects have the live stats attached to them. But say a user wanted to go back and check what someone’s stats were in the last game for instance…

The current method I use just updates the Player Object stats and displays them. That works fine. BUT, it overwrites the live stats. So when they return to their live in progress game, all the stats are wrong, because they’ve been reset to the old, completed game. So I need a way to show these stats, that doesn’t affect a live game. They need to be of type Player as that’s what my table expects.

So I was thinking of faking Player objects that can just be discarded. I’ve tried this though

playersLists = records.map({
(record: GameRecord) → Player in
let fakePlayer = Player()
fakePlayer.name = “TEST”
return fakePlayer

But I get: error: Failed to call designated initializer on NSManagedObject class. So just wondered what is the best method for doing this?