Skip to content

Latest commit

 

History

History
113 lines (86 loc) · 3.03 KB

File metadata and controls

113 lines (86 loc) · 3.03 KB

Fix Compilation Errors in Xcode

Root Cause

The project is compiling BOTH iOS and macOS files together, causing:

  • Duplicate class definitions
  • Platform-specific code conflicts
  • Invalid redeclarations

Immediate Fix in Xcode

Step 1: Exclude iOS Files from macOS Target

  1. Select the Project → Click "Pets Therapy" in navigator
  2. Select Target → Choose "Pets Therapy" (macOS, not Mobile)
  3. Go to Build Settings tab
  4. Search for: "Excluded Source File Names"
  5. Double-click the setting for Debug and Release
  6. Add these exclusion patterns:
    **/iOS/**
    **/NoStatusBar.swift
    **/MobileSettings.swift
    

Step 2: Clean Specific Problem Files

In Build Phases → Compile Sources, remove these if present:

  • StatusBar/NoStatusBar.swift (iOS-only file)
  • Settings/iOS/MobileSettings.swift (iOS-only)
  • Any file with /iOS/ in its path

Step 3: Platform-Specific Compilation

For files that MUST be in both targets but have platform differences:

  1. Go to Build Settings
  2. Search: "Active Compilation Conditions"
  3. Ensure these are set:
    • Debug: DEBUG MACOS
    • Release: MACOS

Step 4: Fix the AppConfig.swift Error

The error "Reference to member 'shared' cannot be resolved" at line 32 needs context.

  1. Open Sources/Models/AppConfig.swift
  2. Line 32 likely has something like .shared without specifying the type
  3. Add the full type, e.g., change:
    • From: .shared
    • To: AppConfig.shared or SomeClass.shared

Step 5: Complete Rebuild

  1. Product → Clean Build Folder (⌘+⇧+K)
  2. Close Xcode
  3. Delete DerivedData:
    rm -rf ~/Library/Developer/Xcode/DerivedData/Pets_Therapy-*
  4. Reopen Xcode
  5. Product → Build (⌘+B)

File-Specific Fixes

StatusBar Files

  • Keep: StatusBar/StatusBar.swift (macOS)
  • Exclude: StatusBar/NoStatusBar.swift (iOS stub)

Settings Files

  • macOS Settings (keep in macOS target):

    • Settings/macOS/DesktopInteractionsSettings.swift
    • Settings/macOS/LaunchAtLoginSettings.swift
    • Settings/macOS/MenuBarSwitch.swift
    • Settings/macOS/ScreensSettings.swift
    • Settings/macOS/AISettings.swift
  • iOS Settings (exclude from macOS target):

    • Settings/iOS/MobileSettings.swift

Alternative: Conditional Compilation

If some files MUST be shared, use conditional compilation:

#if os(macOS)
    // macOS-specific code
    import AppKit
#elseif os(iOS)
    // iOS-specific code
    import UIKit
#endif

Verification

After fixing, you should see:

  • ✅ No "Invalid redeclaration" errors
  • ✅ No "Ambiguous use" errors
  • ✅ Clean build succeeds
  • ✅ Only platform-appropriate files compile for each target

Quick Terminal Fix

Run this to see which files are problematic:

# Find all iOS-specific files
find Sources/swift/Sources -path "*/iOS/*" -name "*.swift" -type f

# Find duplicate class definitions
grep -r "class StatusBarCoordinator" Sources/swift/Sources/

The key is ensuring iOS files are NOT compiled in the macOS target!