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
Related
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 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
I am from Objective-C background but I am using some libraries which are written in Swift .As long as I use xcode 7.3 I am not facing any issues. But after upgrading to Xcode 8 I am prompted to convert to Swift 3.0. I chose later, but
I get the following 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"
I followed this link but no use.
I am getting some error as:
'inout' before a parameter name is not allowed, place it before the
parameter type instead' for ObjectMapper frame work.
For ObjectMapper framework with swift3 compatibility update pod with pod 'ObjectMapper', '~> 2.0', Then clean & re-build, should resolve your problem for swift3. :)
To avoid such a issue when converting code into Swift3. You must have to choose convert option firstly. It automatically converts the syntax into Swift3. After that uninstall pods(if any). Then install it again(to update versions). After that clean the code and re-buid.This will clearly convert entire code into swift3.
I was able to resolve legacy issue in Xcode 8.2.1 by the following steps :
Step 1: open your pod File and make sure you pod file look something like this
# Uncomment the next line to define a global platform for your
project
platform :ios, '8.0'
target 'yourprojectName' do
# Uncomment the next line if you're using Swift or would like to use
dynamic frameworks
use_frameworks!
# Pods for yourprojectName
pod 'UberRides', :git => 'https://github.com/uber/rides-ios-
sdk.git', :branch => 'swift-3-dev'
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
end
Step2: run the pod install command
Step3: Clear you Derived data : Developer/Xcode/DerivedData you can easily get the path from Xcode->Preferences
Step4: Clean and build your project
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'm trying to migrate my Swift project from Swift 2.3 to Swift 3.0. I'm using the Realm framework for data storage, and it's giving me a headache!
I have tried several times now, and i have manually migrated from Swift 2.2 to Swift 2.3.
But after i used the build in migration assistent, i'm getting the following error.
I can't see which binaries causing the issue this time, but earlier it came up with Realm and RealmSwift framework. I have upgraded the Realm pods to version 1.1.
I have tried Clean Build my folder several times, and i have deleted everthing inside DerivedData, but the same issue still persist.
Any suggestions?
In your Podfile, add use_frameworks! and pod 'RealmSwift' to your main and test targets. Paste the following at the bottom of your Podfile updating the Swift version to 3.0:
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
Source: https://realm.io/docs/swift/latest/#installation
Credit for this goes to jpsim.