I'm trying to add delete functionality to my app and I am wondering how I can fix this error Cannot use mutating member on immutable value: 'favSet' is a get-only property.
class FavouriteManager {
static let shared = FavouriteManager()
var favSet: OrderedSet<CurrentPlayers> = OrderedSet()
func add(_ player: CurrentPlayers) {
favSet.append(player)
NotificationCenter.default.post(
name: .passFavNotification,
object: player
)
}
}
var favSet: OrderedSet<CurrentPlayers> {
FavouriteManager.shared.favSet
}
//delete function
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
tableView.beginUpdates()
favSet.remove(at: favSet.index(favSet.startIndex, offsetBy: indexPath.row)) //this is where the error is
tableView.deleteRows(at: [indexPath], with: .fade)
tableView.endUpdates()
}
}