How to exclude Swift files from linting/compilation while keeping them visible in Xcode project?

3 days ago 3
ARTICLE AD BOX

I have old Swift files in my Xcode project that I want to keep for reference, but they're causing compiler errors because they define structs with the same names as my current code.

Project Structure:

scratch/ ├── code/ │ ├── Assets │ ├── current (active file) │ └── Info └── archive/ ├── test1 ├── test2 ├── test3 └── test4

Minimal Reproducible Example:

code/current file:

import SwiftUI @main struct SimpleMenuBarApp: App { var body: some Scene { MenuBarExtra { } label: { Image(systemName: "hammer.fill") .renderingMode(.template) .resizable() .scaledToFit() .frame(width: 18, height: 18) } .menuBarExtraStyle(.window) } }

archive/test1 (and similar files):

// Contains duplicate struct definitions struct SimpleMenuBarApp: App { // ... old implementation }

Error:

Build Failed | Today at 6:47 pm Invalid redeclaration of 'SimpleMenuBarApp'

What I've tried:

Excluded Source File Names build setting:

archive/* archive/ (without the *) test1, test2, test3, test4 (individual file names)

Sub-Directories to Exclude in Recursive Searches build setting:

archive

Moving files outside my source code folder. (moved them from code to archive)

Following this answer - did not work, and it specifically targets compilation, not linting/error detection

Xcode version 26.2

RowSalmon's user avatar

3

Read Entire Article