Alamofire: “Use Legacy Swift Language Version” with pod 'Alamofire', '~> 4.0'

Created on 14 Sep 2016  ·  27Comments  ·  Source: Alamofire/Alamofire

I have to convert my project from XCode 7 to 8. But and i have following in my pod file: pod 'Alamofire', '~> 4.0'

And i get this error on compilation.

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

How to fix this.

support

Most helpful comment

Have you tried this? http://stackoverflow.com/a/38466703/1054550

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '3.0'
        end
    end
  end

All 27 comments

Have the same error

Same here

Have you tried this? http://stackoverflow.com/a/38466703/1054550

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '3.0'
        end
    end
  end

Thanks! Worked for me. Hope there are no side-effects.

I'm having the same issue and the above fix resulted in:

Module file was created by an older version of the compiler; rebuild 'Alamofire' and try again:
.../path/to/Alamofire.framework/Modules/Alamofire.swiftmodule/arm64.swiftmodule

Here's my Podfile if it helps..

platform :ios, '9.0'
use_frameworks!

target 'my-project' do

  pod 'Firebase'
  pod 'Firebase/Auth'
  pod 'Firebase/Messaging'
  pod 'ChameleonFramework/Swift', :git => 'https://github.com/ViccAlexander/Chameleon.git', :branch => 'swift3'
  pod 'SwiftyJSON', :git => 'https://github.com/acegreen/SwiftyJSON.git', :branch => 'swift3'
  pod 'Alamofire', '~> 4.0'

end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['SWIFT_VERSION'] = '3.0'
    end
  end
end

EDIT: Seem to have fixed it by deleting my app's entry in DerivedData and cleaning the project

@ostatnicky's workaround should not be necessary if you're using CocoaPods 1.1.0, as it adds that setting to your Pods project automatically. As with any upgrade of Xcode and dependencies, clearing your DerivedData folder is always a good idea.

Hi,
I even deleted derived folder added above code in Podfile but still getting same error "“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly."

What exactly need to change?

Thanks,
Amir

@amirpervaiz086 update your cocoapods

  1. sudo gem install cocoapods --pre
  2. pod install

when I run above command it says:

ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj

@mengheangrat my current pod version is 1.0.1

update your pod version to
1.1.0.rc.2

screen shot 2016-09-22 at 9 55 51 am

Hi @mengheangrat. I successfully upgraded to 1.1.0.rc.2 but when I run pod install it says this:

Setting up CocoaPods master repo
Unknown option: -C
usage: git [--version] [--help] [-c name=value]
[--exec-path[=]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=] [--work-tree=] [--namespace=]
[]
[!] Unable to add a source with url https://github.com/CocoaPods/Specs.git named master-1.
You can try adding it manually in ~/.cocoapods/repos or via pod repo add.

it was never happened with pod 1.0.1. Any idea?

use terminal

cd ~/.cocoapods/repos
cd master || if don't have should create by using mkdir master
git clone https://github.com/CocoaPods/Specs.git into master folder

thanks man. I manually installed but 'pod install' says:
[!] Unable to add a source with url https://github.com/CocoaPods/Specs.git named master-1. so I renamed master folder to master-1 and now when I run 'pod install' its stuck on 'Setting up CocoaPods master repo..' on terminal. Seems like its taking time in setting up. let me know if I am doing it wrong.

Thanks.

Yes, you have to wait it until finish, because it has big size.

@amirpervaiz086 sudo gem install -n /usr/local/bin cocoapods --pre this worked for me.

@mengheangrat thanks man. I waited for 15 mins and cancelled it since it didnt show any progress... but gonna try again now. I really need to fix it out. Thanks for your help.

@cnrblm yes it worked for me too.

@mengheangrat Still getting error when I run "Pod install"

RuntimeError - Unable to create a source with URL https://github.com/CocoaPods/Specs.git
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/sources_manager.rb:42:in find_or_create_source_with_url' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/analyzer.rb:784:inblock in sources'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/analyzer.rb:783:in map' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer/analyzer.rb:783:insources'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:143:in resolve_dependencies' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/installer.rb:110:ininstall!'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/command/install.rb:37:in run' /Library/Ruby/Gems/2.0.0/gems/claide-1.0.0/lib/claide/command.rb:334:inrun'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/lib/cocoapods/command.rb:50:in run' /Library/Ruby/Gems/2.0.0/gems/cocoapods-1.1.0.rc.2/bin/pod:55:in /usr/local/bin/pod:23:in load' /usr/local/bin/pod:23:in

'

i try this , and it work for me.

platform :ios, '9.0'
use_frameworks!

target 'mkhPush' do
pod 'Alamofire', '~> 3.3'
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3'
end
end
end

See this link. He explains, what's going on in detail. And how to fix it.

@ostatnicky's solution worked for me too.

happen to the same problem! must i update my cocoapods to 1.1.0 version to solve this problem?..
who can help me? tks

OK! i have solved it!
you can read Swift开发使用Cocoapods引入第三方库异常处理方法

I just do Edit->Convert->Current Swift Syntax and error has gone. I did't make any changes in code or Xcode.

It works for me.

Was this page helpful?
0 / 5 - 0 ratings