Repository: CodeEditApp/CodeEdit
File: CodeEdit/Features/Welcome/Model/RecentProjectsStore.swift (Swift)

Code before:
//
//  RecentProjectsUtil.swift
//  CodeEdit
//
//  Created by Khan Winter on 10/22/24.
//

import AppKit
import CoreSpotlight

/// Helper methods for managing the recent projects list and donating list items to CoreSpotlight.
///
/// Limits the number of remembered projects to 100 items.
///
/// If a UI element needs to listen to changes in this list, listen for the
/// ``RecentProjectsStore/didUpdateNotification`` notification.
class RecentProjectsStore {
    /// The default projects store, uses the `UserDefaults.standard` storage location.
    static let `default` = RecentProjectsStore()

    private static let projectsdDefaultsKey = "recentProjectPaths"
    static let didUpdateNotification = Notification.Name("RecentProjectsStore.didUpdate")

    /// The storage location for recent projects
    let defaults: UserDefaults

    /// Create a new store with a `UserDefaults` storage location.
    init(defaults: UserDefaults = UserDefaults.standard) {
        self.defaults = defaults
    }

    /// Gets the recent paths array from `UserDefaults`.
    private func recentPaths() -> [String] {
        defaults.array(forKey: Self.projectsdDefaultsKey) as? [String] ?? []
    }

    /// Gets all recent paths from `UserDefaults` as an array of `URL`s. Includes both **projects** and
    /// **single files**.
    /// To filter for either projects or single files, use ``recentProjectURLs()`` or ``recentFileURLs``, respectively.
    func recentURLs() -> [URL] {
        recentPaths().map { URL(filePath: $0) }
    }

    /// Gets the recent **Project** `URL`s from `UserDefaults`.

Review comment (suggestion):
```suggestion
    static let shared = RecentProjectsStore()
```
In Swift, singleton objects are typically named using conventions like `shared` or `standard`.

Code after:
//
//  RecentProjectsUtil.swift
//  CodeEdit
//
//  Created by Khan Winter on 10/22/24.
//

import AppKit
import CoreSpotlight
import OSLog

/// Helper methods for managing the recent projects list and donating list items to CoreSpotlight.
///
/// Limits the number of remembered projects to 100 items.
///
/// If a UI element needs to listen to changes in this list, listen for the
/// ``RecentProjectsStore/didUpdateNotification`` notification.
class RecentProjectsStore {
    private let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "", category: "RecentProjectsStore")

    /// The default projects store, uses the `UserDefaults.standard` storage location.
    static let shared = RecentProjectsStore()

    private static let projectsdDefaultsKey = "recentProjectPaths"
    static let didUpdateNotification = Notification.Name("RecentProjectsStore.didUpdate")

    /// The storage location for recent projects
    let defaults: UserDefaults

    #if DEBUG
    /// Create a new store with a `UserDefaults` storage location.
    init(defaults: UserDefaults = UserDefaults.standard) {
        self.defaults = defaults
    }
    #else
    /// Create a new store with a `UserDefaults` storage location.
    private init(defaults: UserDefaults = UserDefaults.standard) {
        self.defaults = defaults
    }
    #endif

    /// Gets the recent paths array from `UserDefaults`.
    private func recentPaths() -> [String] {
        defaults.array(forKey: Self.projectsdDefaultsKey) as? [String] ?? []