iOS Objective-C依赖错误求助:需配置SWIFT_VERSION至支持版本
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
Podfileand add this snippet for your target (replaceYourTargetNamewith 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 installagain 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

