Whenever I try to persist an object to the DB using insert
or upsert
, Xcode complains Cannot use mutating member on immutable value
.
I understand why Xcode is complaining, but do I really have to make a copy of the function parameter just to save? It seems so hacky. Perhaps there's a better way?
static func saveWorkoutTemplate(wt: WorkoutTemplate) {
guard let dbQueue = openDB() else { return }
var w = wt //lame hack
try! dbQueue.write { db in
try! w.upsert(db) // this works
//try! wt.upsert(db) // error: Cannot use mutating member on immutable value: 'wt' is a 'let' constant
}
}