I recently migrated my Swift 2.3 SDK Project to Swift 3 using the XCode Swift Migrator. After doing so, I updated my pod dependencies (AlamoFire - 4.4.0 and SwiftyJSON - 3.1.4) to use their respective Swift 3 Versions.
Unfortunately, after this, my project did not build. I am getting the following errors:
Module compiled with Swift 2.3 cannot be imported in Swift 3.0.2:
.../Alamofire.framework/Modules/Alamofire.swiftmodule/x86_64.swiftmodule
I've set all the "Use Legacy Swift Language Version" to "NO" but still nothing.
I've "clean & build" project and "closed & reopen" workspace to no avail.
What else could I be possibly missing? How can I fix this?
Thanks.
Delete the pods from the pod file.
Quit Xcode.
Try to uninstall them by using the command pod install. This will update your project and delete all of the existing pods correctly.
Open Xcode and clean your project (and eventually try to build it once) and make sure the pods are gone.
Add the pods again to your pods file and run pod install again.
This is a general fix that could do it. It worked for me several times.
Try adding this in your pod file after all the pods and run pod install again...
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
Related
I'm using Xcode 10.2, Swift 5.
With Debug scheme, no issue happens, but with Release scheme when I build or archive, it shows Command compileSwift failed with a nonzero exit code.
I've tried delete DerivedData / Clean / pod deintegrate & pod install & pod update. None of these works.
For my project problem was related to pod Cache which gives error when Optimization Level for Release is set to Optimize for Speed [-O]. I have set Compilation Mode to Whole Module again and set optimization level for the pod in pod file:
post_install do |installer|
installer.pods_project.targets.each do |target|
# Cache pod does not accept optimization level '-O', causing Bus 10 error. Use '-Osize' or '-Onone'
if target.name == 'Cache'
target.build_configurations.each do |config|
level = '-Osize'
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = level
puts "Set #{target.name} #{config.name} to Optimization Level #{level}"
end
end
end
end
Refrence: https://github.com/hyperoslo/Cache/issues/233#issuecomment-477749560
I fixed this issue by going Pods Project then to the building settings and setting Compilation Mode to Incremental for Release. Then clean and archive, should compile fine then.
So I had same issue when updating my project to Swift 5.
For some reason, Cocoapods (latest version, 1.6.1) set the SWIFT_VERSION of some pods to Swift 5 even if they're released as Swift 4, 4.1, 4.2 pods.
So I had to add a post install script that set the correction version of swift like so
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'CryptoSwift' || target.name == 'SwiftyBeaver'
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.2'
end
end
end
end
I had the same issue after upgrading to Xcode 10.2. After following the steps below it worked for me:
Update pods
Clean project folder
Change Pods project's Swift Language Version to Unspecified and (as suggested by #Neil Faulkner) Compilation Mode to Incremental
I had to set "Optimization Level" in "Swift Compiler - Code Generation" to "Release" - "No Optimization [-Onone]" from "Optimize for speed" to make Cache pass Archive.
Same with SwiftyBeaver
It seems a problem related to Xcode 10.2. Also other pod projects seems to be fine with Optimization, like Toucan or XCGLogger.
In my case it just appeared probably because I ran project again while it was building.
So what I did was not only clean but also folder clean my project using
SHITF + ALT + COMMAND + K
also I deleted derived data and the project was up and running again.
you can follow this steps...
Make sure to change Swift version to your current version.
Update all your pods.
Clean all derived data of Xcode.
Now Restart your Mac.
You are getting all those error's just because of pods..so either you need to update every pod that you are using.
I'm using Xcode 10.2, Swift 5.
With Debug scheme, no issue happens, but with Release scheme when I build or archive, it shows Command compileSwift failed with a nonzero exit code.
I've tried delete DerivedData / Clean / pod deintegrate & pod install & pod update. None of these works.
For my project problem was related to pod Cache which gives error when Optimization Level for Release is set to Optimize for Speed [-O]. I have set Compilation Mode to Whole Module again and set optimization level for the pod in pod file:
post_install do |installer|
installer.pods_project.targets.each do |target|
# Cache pod does not accept optimization level '-O', causing Bus 10 error. Use '-Osize' or '-Onone'
if target.name == 'Cache'
target.build_configurations.each do |config|
level = '-Osize'
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = level
puts "Set #{target.name} #{config.name} to Optimization Level #{level}"
end
end
end
end
Refrence: https://github.com/hyperoslo/Cache/issues/233#issuecomment-477749560
I fixed this issue by going Pods Project then to the building settings and setting Compilation Mode to Incremental for Release. Then clean and archive, should compile fine then.
So I had same issue when updating my project to Swift 5.
For some reason, Cocoapods (latest version, 1.6.1) set the SWIFT_VERSION of some pods to Swift 5 even if they're released as Swift 4, 4.1, 4.2 pods.
So I had to add a post install script that set the correction version of swift like so
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'CryptoSwift' || target.name == 'SwiftyBeaver'
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.2'
end
end
end
end
I had the same issue after upgrading to Xcode 10.2. After following the steps below it worked for me:
Update pods
Clean project folder
Change Pods project's Swift Language Version to Unspecified and (as suggested by #Neil Faulkner) Compilation Mode to Incremental
I had to set "Optimization Level" in "Swift Compiler - Code Generation" to "Release" - "No Optimization [-Onone]" from "Optimize for speed" to make Cache pass Archive.
Same with SwiftyBeaver
It seems a problem related to Xcode 10.2. Also other pod projects seems to be fine with Optimization, like Toucan or XCGLogger.
In my case it just appeared probably because I ran project again while it was building.
So what I did was not only clean but also folder clean my project using
SHITF + ALT + COMMAND + K
also I deleted derived data and the project was up and running again.
you can follow this steps...
Make sure to change Swift version to your current version.
Update all your pods.
Clean all derived data of Xcode.
Now Restart your Mac.
You are getting all those error's just because of pods..so either you need to update every pod that you are using.
Apparently I have managed to build my project in Xcode 9 beta and now I only get the error
Module compiled with swift 4.0 cannot be imported in swift 3.1
When I run the project in Xcode 8. The module in my case are Alamofire. I have tried to restart Xcode but nothing happens any ideas how to solve this issue?
You have two options that you can do:
Clean the project and then try to re-build your solution and see if it works.
If it don´t work and you still get the same error message then do the following steps and it should work for you:
Open your podfile and remove Alamofire
Run pod update
Re-add Alamofire to your podfile
Run pod update
When this is done, clean your project and run it
Same problem here but using Carthage. And here is the answer:
rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
delete the Carthage folder for the project
Update Carthage: carthage update --platform iOS
And voilà!
I had the same problem and cleaning the build folder helped:
Command+Option+Shift+K
or
Product -> Option+Clean
Just deleting Derived data worked for me, no need to do Pod install again
I met this problem in a project where dependency is managed by Carthage. In my case, I didn't set command line tool in xcode (Type in xcodebuild -version, you will know whether you set it up or not), so first step is to go to XCode --> Preference --> Locations then select the xcode you want to serve as command line tool. Then you can follow the steps that #Domsware mentioned above to rebuild all frameworks you are gonna use.
===============================================
Same problem here but using Carthage. And here is the answer:
rm -rf ~/Library/Caches/org.carthage.CarthageKit/DerivedData
delete the Carthage folder for the project
Update Carthage: carthage update --platform iOS
===============================================
Then don't forget to delete old links under 'Linked frameworks and libraries' and drag all frameworks from /Carthage folder under you project to 'Linked frameworks and libraries'.
Then voilà!
For those who are using CocoaPods, I suspect (Disclaimer: I didn't encounter this problem in project where CocoaPods is the dependency manager) the solution would be run the following command in terminal:
$ pod deintegrate
$ pod clean
$ pod install
where you might need to install 'deintegrate' and 'clean' tool for CocoaPod
$ sudo gem install cocoapods-deintegrate cocoapods-clean
more details see post
How to remove CocoaPods from a project?
Add following lines at the end of your pod file:
post_install do |installer|
print "Setting the default SWIFT_VERSION to 4.0\n"
installer.pods_project.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
installer.pods_project.targets.each do |target|
if ['SomeTarget-iOS', 'SomeTarget-watchOS'].include? "#{target}"
print "Setting #{target}'s SWIFT_VERSION to 3.0\n"
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
else
print "Setting #{target}'s SWIFT_VERSION to Undefined (Xcode will automatically resolve)\n"
target.build_configurations.each do |config|
config.build_settings.delete('SWIFT_VERSION')
end
end
end
end
I installed the new XCode 8 and trying to run my project. Some of the Pods i use were not update yet to Swift 2.3/3.0 and the project won't compile. How can i use older Pods in my project?
Please check procedures here that will make your swift 2.2 or swift 2.3 pods compatible with Xcode8 as its.
As steps:
To begin, open your project in Xcode 7. Go to project settings, open the Build settings tab, and click the “+” to add a User-Defined Setting: SWIFT_VERSION = 2.3
In your Podfile you should put the following post install script. Don't forget to replace YOURTEAMID with your own
post_install do |installer|
installer.pods_project.build_configurations.each do |config|
# Configure Pod targets for Xcode 8 compatibility
config.build_settings['SWIFT_VERSION'] = '2.3'
config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = 'YOURTEAMID/'
config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'
end
en
Keep in mind that will work fine with most Pods, but not all I still struggling with Eureka pod to work.
I just want to try Swift 3.0 in one of my projects. Xcode open the migration window to update my project to use Swift 3.0.
The problem is, I just want to to update my project, and leave the Pods project untouched because any changes will be discard after I run the pod install again.
Anyone already have a solution for that?
What you're asking is not possible. Xcode builds your Cocoapods dependencies as well as your project. You cannot mix Swift 2.x and Swift 3 code in the same project or use Cocoapods with Swift 3 that are written in Swift 2.x.
Just use the following commands in the end of your podfile and it sets up your pods file to have the frameworks take the swift 3 compiler or legacy compiler automatically so you do not get the cannot use swift 2.1 in swift 3 and errors like that.
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
Using this, have a look at the following example of my podfile. Just make sure the end statement is not before the block I have written above.
platform :ios, '8.0'
use_frameworks!
target 'Project 1'
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'
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
This might help Swift migration guide
Straight from Swift.org
Using Carthage/CocoaPods Projects
If you are using binary Swift modules from other projects that are not built along with your project in your Xcode workspace, you can choose from one of the following migration strategies:
Include the source code of the project in your Xcode workspace With
this approach you will build and migrate the open-source project
along with your own project.
Use Xcode 7.3[.1] to make the necessary changes and validate that
the project builds and links everything correctly.
Include the other Xcode project files in your workspace and setup
your scheme for building the targets that your project depends on.
If you have setup framework search paths for finding the binary
Swift modules inside Carthage’s build folder, either remove the
search paths or clean the build folder, so that you are sure that
you are only using the Swift modules that are built from your Xcode
workspace.
Wait until the upstream open-source project updates to Swift 2.3 or Swift 3
You can follow this workflow for migrating your project:
Keep your project as it is building with Xcode 7.3
Invoke the migration assistant and apply the source changes that are
suggested for your own project only (for Swift 2.3 or Swift 3)
Before trying to build, modify the Carthage/CocoaPods dependency
file and specify the specific tag/branch of the project that is
migrated to Swift 2.3 or Swift 3; update your dependencies and try
to build your project with the updated dependencies and the source
changes that you got from the migrator.
any xcode in use latest cocoapods and remove cocoapods and again install latest with this step surly work in swift 3.0 i used in swift 3.0
0.sudo gem install cocoapods
1.cd (drag and drop your project folder)
2.sudo gem install cocoapods
3.touch podfile //create podfile
4.open -e podfile
5.platform :ios, '10.0'
use_frameworks!
target '' do
pod 'Alamofire', '~> 4.4'
end
6.ctrl+s
7.ctrl+q
8.pod install