mirror of
https://github.com/NinjaCheetah/RIT-Dining.git
synced 2026-01-17 12:05:57 -05:00
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.
39 lines
823 B
Swift
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)
|
|
}
|
|
}
|