Repository: CodeEditApp/CodeEdit
File: CodeEdit/Documents/WorkspaceDocument.swift (Swift)

Code before:
        )
        self.addWindowController(windowController)
    }

    // MARK: Set Up Workspace

    private func initWorkspaceState(_ url: URL) throws {
        self.workspaceClient = try .default(
            fileManager: .default,
            folderURL: url,
            ignoredFilesAndFolders: ignoredFilesAndDirectory
        )
        self.searchState = .init(self)
        self.quickOpenState = .init(fileURL: url)
        self.statusBarModel = .init(workspaceURL: url)

        NotificationCenter.default.addObserver(self,
                                               selector: #selector(convertTemporaryTab),
                                               name: NSNotification.Name("CodeEditor.didBeginEditing"),
                                               object: nil)
    }

    private func readSelectionState() throws -> WorkspaceSelectionState {
        guard let path = fileURL?.path,
              let pathData = path.data(using: .utf8) else { return selectionState }
        let hash = String(CryptoKit.SHA256.hash(data: pathData).hashValue)
        if let data = UserDefaults.standard.value(forKey: hash) as? Data {
            let state = try PropertyListDecoder().decode(WorkspaceSelectionState.self, from: data)
            return state
        }
        return selectionState
    }

    override func read(from url: URL, ofType typeName: String) throws {
        try initWorkspaceState(url)

        // Initialize Workspace
        do {
            selectionState = try readSelectionState()
        } catch {
            Swift.print("couldn't retrieve selection state from user defaults")
        }

        workspaceClient?
            .getFiles
            .sink { [weak self] files in
                guard let self = self else { return }

                guard !self.fileItems.isEmpty else {
                    self.fileItems = files
                    return

Review comment (suggestion):
`.hashValue` will not be equal across executions of the program ([source](https://developer.apple.com/documentation/swift/string/hashvalue)).

Consider implementing it something like that:

```swift
let stringData = "Hello World".data(using: .utf8)!

let hash = SHA256.hash(data: stringData)

let hashString = hash.compactMap { String(format: "%02x", $0) }.joined()
```

Code after:
        self.addWindowController(windowController)
    }

    // MARK: Set Up Workspace

    private func initWorkspaceState(_ url: URL) throws {
        self.workspaceClient = try .default(
            fileManager: .default,
            folderURL: url,
            ignoredFilesAndFolders: ignoredFilesAndDirectory
        )
        self.searchState = .init(self)
        self.quickOpenState = .init(fileURL: url)
        self.statusBarModel = .init(workspaceURL: url)

        NotificationCenter.default.addObserver(self,
                                               selector: #selector(convertTemporaryTab),
                                               name: NSNotification.Name("CodeEditor.didBeginEditing"),
                                               object: nil)
    }

    /// Retrieves selection state from UserDefaults using SHA256 hash of project  path as key
    /// - Throws: `DecodingError.dataCorrupted` error if retrived data from UserDefaults is not decodable
    /// - Returns: retrived state from UserDefaults or default state if not found
    private func readSelectionState() throws -> WorkspaceSelectionState {
        guard let path = fileURL?.path,
              let hash = path.sha256Hash,
              let data = UserDefaults.standard.value(forKey: hash) as? Data  else { return selectionState }
        let state = try PropertyListDecoder().decode(WorkspaceSelectionState.self, from: data)
        return state
    }

    override func read(from url: URL, ofType typeName: String) throws {
        try initWorkspaceState(url)

        // Initialize Workspace
        do {
            selectionState = try readSelectionState()
        } catch {
            Swift.print("couldn't retrieve selection state from user defaults")
        }

        workspaceClient?
            .getFiles
            .sink { [weak self] files in
                guard let self = self else { return }

                guard !self.fileItems.isEmpty else {
                    self.fileItems = files
                    return
                }