You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS Objective-C依赖错误求助:需配置SWIFT_VERSION至支持版本

Fixing the "SWIFT_VERSION must be set to a supported value" Error in iOS Development

Hey there, I’ve run into this exact issue a few times when working with mixed Swift/Objective-C projects, so let’s break down how to fix it quickly:

Step 1: Select the Correct Target in Xcode

First, make sure you’re editing the right target (not the project itself). In Xcode’s left sidebar, click on your project name, then select the Swift-based target that’s throwing the error from the list under "Targets".

Step 2: Navigate to Build Settings

Click on the "Build Settings" tab at the top. If you don’t see all settings, toggle the "All" button (instead of "Basic") to show every available configuration.

Step 3: Find and Set SWIFT_VERSION

  • Use the search bar at the top right of the Build Settings panel to search for SWIFT_VERSION.
  • You’ll see a row labeled "Swift Language Version"—click on the current value (it might be empty or set to an outdated version).
  • From the dropdown menu, select a supported Swift version (usually the latest stable version compatible with your Xcode version, like Swift 5.9 if you’re on Xcode 15).

Bonus: Check Dependencies (If Using CocoaPods)

If your Swift target depends on an Objective-C pod, sometimes the pod’s target might inherit incorrect settings. Here’s a quick fix:

  • Open your Podfile and add this snippet for your target (replace YourTargetName with your actual target name):
    target 'YourTargetName' do
      use_frameworks!
      # Your pods here...
      
      post_install do |installer|
        installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '5.9' # Match your main target's Swift version
          end
        end
      end
    end
    
  • Run pod install again to apply the changes.

Verify the Fix

After setting the SWIFT_VERSION, clean your project (Cmd + Shift + K) and rebuild (Cmd + B). The error should disappear if everything’s configured correctly.

Pro tip: Make sure all targets in your project (including test targets) have the same SWIFT_VERSION set to avoid similar issues down the line.

内容的提问来源于stack exchange,提问作者Salon Seat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 10:05:15