WallPaperHome722/WallpaperHD_Live/Tool/imagename.swift
2024-07-25 19:20:41 +08:00

49 lines
1.4 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// historyManager.swift
// WallpaperHD_Live
import Foundation
class ImageNameManager {
// UserDefaults
private let key = "imageNames"
//
func getImageNames() -> [String] {
return UserDefaults.standard.stringArray(forKey: key) ?? []
}
//
func addImageName(_ imageName: String) {
var imageNames = getImageNames()
//
if !imageNames.contains(imageName) {
//
imageNames.append(imageName)
// UserDefaults
UserDefaults.standard.set(imageNames, forKey: key)
print("Added new image name: \(imageName)")
} else {
print("Image name already exists: \(imageName)")
}
}
//
func removeImageName(_ imageName: String) {
var imageNames = getImageNames()
//
if let index = imageNames.firstIndex(of: imageName) {
imageNames.remove(at: index)
// UserDefaults
UserDefaults.standard.set(imageNames, forKey: key)
print("Removed image name: \(imageName)")
} else {
print("Image name not found: \(imageName)")
}
}
}