mirror of
https://github.com/NinjaCheetah/RIT-Dining.git
synced 2026-03-05 05:25:29 -05:00
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.
This commit is contained in:
51
TigerDine/Data/DietaryRestrictions.swift
Normal file
51
TigerDine/Data/DietaryRestrictions.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// DietaryRestrictions.swift
|
||||
// TigerDine
|
||||
//
|
||||
// Created by Campbell on 11/11/25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
enum Allergen: String, Codable, CaseIterable {
|
||||
case coconut
|
||||
case egg
|
||||
case gluten
|
||||
case milk
|
||||
case peanut
|
||||
case sesame
|
||||
case shellfish
|
||||
case soy
|
||||
case treenut
|
||||
case wheat
|
||||
}
|
||||
|
||||
@Observable
|
||||
class DietaryRestrictions {
|
||||
private var dietaryRestrictions: Set<String>
|
||||
private let key = "DietaryRestrictions"
|
||||
|
||||
init() {
|
||||
let favorites = UserDefaults.standard.array(forKey: key) as? [String] ?? [String]()
|
||||
dietaryRestrictions = Set(favorites)
|
||||
}
|
||||
|
||||
func contains(_ restriction: Allergen) -> Bool {
|
||||
dietaryRestrictions.contains(restriction.rawValue)
|
||||
}
|
||||
|
||||
func add(_ restriction: Allergen) {
|
||||
dietaryRestrictions.insert(restriction.rawValue)
|
||||
save()
|
||||
}
|
||||
|
||||
func remove(_ restriction: Allergen) {
|
||||
dietaryRestrictions.remove(restriction.rawValue)
|
||||
save()
|
||||
}
|
||||
|
||||
func save() {
|
||||
let favorites = Array(dietaryRestrictions)
|
||||
UserDefaults.standard.set(favorites, forKey: key)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user