RIT-Dining/TigerDine/Data/Favorites.swift
NinjaCheetah 23ebc9d848
Replace all instances of "RIT Dining" with "TigerDine"
The project and some files were still named that way, so that's been fixed now. The bundle ID is stuck that way forever but oh well. Nobody will see that.
2025-12-24 16:41:18 -05:00

39 lines
823 B
Swift

//
// Favorites.swift
// TigerDine
//
// Created by Campbell on 9/22/25.
//
import SwiftUI
@Observable
class Favorites {
private var favoriteLocations: Set<Int>
private let key = "Favorites"
init() {
let favorites = UserDefaults.standard.array(forKey: key) as? [Int] ?? [Int]()
favoriteLocations = Set(favorites)
}
func contains(_ location: DiningLocation) -> Bool {
favoriteLocations.contains(location.id)
}
func add(_ location: DiningLocation) {
favoriteLocations.insert(location.id)
save()
}
func remove(_ location: DiningLocation) {
favoriteLocations.remove(location.id)
save()
}
func save() {
let favorites = Array(favoriteLocations)
UserDefaults.standard.set(favorites, forKey: key)
}
}