Xcode 9 Release Notes says that Swift 3 compilation is supported:
One compiler for Swift 4 and Swift 3, Swift 4 and Swift 3 targets can be compiled together in the same project.
I have installed Xcode 9 beta.
But when I press Build it shows bunch of errors. Are some special preparations need to do when use Swift 3 in Xcode 9?
UPD:
Module compiled with Swift 3.1 cannot be imported in Swift 4.0
Select the target, goto Build Settings > Swift Language Version:
All the above answers are answering the wrong question. When using Xcode 9, you are using the Swift 4 compiler (even if you are using it to compile Swift 3 code) to fix this, recompile using the appropriate compiler/Xcode.
If you are trying to do this via commandline, you can use sudo xcode-select -switch to switch between xcode versions. Good luck!
Update for Xcode 10.1 and Swift 4.2
Swift 3, 4, and 4.2 targets can coexist and link together.
You decide when and if you’d like to migrate on a per-target basis
when it makes sense for your project. While migrating to Swift 4.2 is
definitely encouraged, it’s not an all-or-nothing process, as Swift 3,
4, and 4.2 targets can coexist and link together.
Different cocoapod and different project version can also coexist.
You wish to have different cocoapod version as compared to your project version then you should make following changes at the end of your pod file:
post_install do |installer|
print "Setting the default SWIFT_VERSION to 4.2\n"
installer.pods_project.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.2'
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
Sometimes even after you run pod update your xcode forcefully update your cocoapod's project version, then in that case select cocoapod pod project and change the swift version in the build settings.
I had same issue - (I installed pod which swift version was 3x and my project's swift version was Swift 4. So I got so many compiler errors. Later I changed the Swift version form 4 to 3.2 and tried to build project, again I got compiler errors. I think that happen because of I run pod install while my project was in Swift 4.)
First you need to change the "Swift language version" from build settings.
If you have installed any pod then changing only "Swift Language Version" won't help. You may need to run pod install for the project.
Xcode 9 needs the framework to be built with Swift 3.2 or higher. Go to https://github.com/emaloney/CleanroomLogger and click Download ZIP. Open the xcodeproj in Xcode 9. Press ⌘B. CleanroomLogger.framework turns from red to black. Drag the framework into your project. See related question: Realm issue with Swift 3.1
Related
I have my project in Xcode 10.1 with Swift 3 and I am using 20+ frameworks and everything was fine till few days ago when some of frameworks decided that they need to release fix for critical bug for iOS 13. So when I update my pods and run my project it said
could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1001.0.46.4.0_0' Reader: '1000.11.45.5_0')', using libLTO version 'LLVM version 10.0.0, (clang-1000.11.45.5)' for architecture arm64
OK so that means that they build their project in newer Xcode then I am working on (I guess they are using the last one 10.3) and then I try to set bitcode to false on my main target but guess what error is the same..
Ok so I download their demo project and this fix about bitcode worked so I am not sure what is wrong with my project why this bitcode = NO does not work. I only disabled bitcode on my main target do I need to set that on some other place or something?
Not sure is this relevant but I have 2 Xcodes parallel 10.1 and 10.3
I have this problem a few days.
This app that I am using is Appboy-iOS-SDK.
We've had similar issues to you with the Braze (Appboy) SDK.
After investigating, we've found that this issue only affects apps built with Xcode 11 or greater, so there's no need to update the SDK unless you're planning to build and submit your app using Xcode 11, which is not required even after iOS 13 is released. We're leaving the SDK at the old version and have found no issue here.
If you would like to update regardless, still using Xcode 10.x you'll need to get around the mismatch by turning off bitcode. To have success with this, you'll need to disable it on both the config for your project/workspace, and for Appboy-iOS-SDK. If you're using Cocoapods to manage dependencies, you would be best off adding this to your Podfile so it doesn't get reset to YES each time you run pod install:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if target.name == 'Appboy-iOS-SDK'
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
end
All that said, I think the answer is just to do this upgrade only when you upgrade your build machine to use Xcode 11.
After updating to Xcode 9, I tried to build one of my projects.
I use the FacebookLogin pod.
I have a compiler error in FacebookLogin/LoginButton.swift
#testable import FacebookCore
❌ Module compiled with Swift 3.1 cannot be imported in Swift 4.0
In my target's build settings, the Swift language version is set to Swift 3.2.
I guess I need to wait for Facebook to update their pod ? Or any other suggestion ?
Thanks !
Update:
Solution also tested and working in Swift 5 and Xcode 11.
Original:
I would like to add that if you are using Carthage to compile a module in Swift 3.2 you should go to a terminal and run:
sudo xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer
To use the Xcode 9 command line tools, then you can run:
carthage update NameOfTheLibrary --platform iOS --no-use-binaries
This will compile the library with your current command line tools, it can be a bit slow but now the project should build.
Note
To revert and use your stable Xcode command line tools simply run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
Xcode 9 comes with a Swift 4 compiler that understands both Swift 3.2 and swift 4, it even lets you mix and match between the 2 versions. Unfortunately, other versions aren't supported.
Even if you set your language to Swift 3.2, it uses the Swift 4 compiler.
If you're using cocoapods, you can add this to the end of your pod file to force the pods to use Swift 3.2 or 4.0:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.2'
end
end
end
Alternatively, you could put the files from the pod directly into your project temporarily, until FacebookLogin is updated to Swift 3.2 or 4.
Note: Edited based on Matt's feedback
Maybe you can clean the target before you build it.
It works fine for me.
I ran into the same issue on Xcode 9 Beta 3, which pointing to 'Alamofire' and tried a few different solutions, the easiest one i found is
1. CMD+SHIFT+K to clean the build
2. Restart Xcode 9 <-- make sure you do this step, that's critical. `
Doing a "clean build folder" and restarting Xcode 9 cleaned up the error for me. Also the error didn't stop the app from running on my device or the simulator.
goto xcode DerivedData directory then remove all file inside it and recompile your project . it work for me .
and default DerivedData directory is :~/Library/Developer/Xcode/DerivedData.
If using Carthage , Open terminal and;
carthage update --platform iOS --no-use-binaries
If using Pod , Open terminal and;
pod update
(Also if don't work in pod, you can change SWIFT_VERSION in podfile Ex:
config.build_settings['SWIFT_VERSION'] = '3.2'
)
After;
Open Xcode and use;
Command+Option+Shift+K
It works for me.
1.Clean your project in Xcode 8
2.Build or run your project in Xcode 9
I cleaned the project in Xcode 9, and then run the app, it works.
I had the same problem with Xcode 9 GM and this solved my problem:
Remove it from the project and drag it again into "Embedded Binaries".
Clean Build Folder
Cmd + option + shift + K
I have
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
in my project and import FBSDKLoginKit, after cleaning the target i didn't have any issue
Since the pod you are using is in swift and is a beta pod, it is likely that you would have some issues with the swift 4 compiler, you should use the objective-c version of the pod for the time being
If you use from Pod:
In Podfile comment FacebookLogin pod
pod install
In Podfile uncomment FacebookLogin pod
pod install
Run again your project
For my case - the actual pod referenced a static zip with prebuilt binaries targeting swift 3.1.
So only solution is to rebuild the framework with source from xcode 9.
https://github.com/AudioKit/AudioKit/issues/980
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
I was wondering whether it is already possible to use Realm with the beta of Swift 3.0.
Although I see a RealmSwift-swift3.0 directory in in the Realm repo, I do not succeed to use it correctly. How should I install it from source?
You can use Realm with Swift 3.0, but take into account that the current version is still absolutely experimental.
You can clone the master branch of the realm-cocoa repo from GitHub.
Or you can use Carthage:
github "realm/realm-cocoa.git" "master"
Or if you prefer CocoaPods:
pod 'RealmSwift', :git => 'https://github.com/realm/realm-cocoa.git', :branch => 'master'
If you use Carthage, remember that you must add Realm and RealmSwift frameworks manually (ignore the IBAnimatable framework):
In fact, I have one of my projects with Xcode 8, Swift 3 and Realm, and it works perfectly :)
Starting from version 1.1.0 Realm is officially compatible with Swift 3.0/Xcode 8.0. See here.
This release brings official support for Xcode 8, Swift 2.3 and Swift
3.0. Prebuilt frameworks are now built with Xcode 7.3.1 and Xcode 8.0.
Here's an extract from the install docs :
If using Xcode 8, paste the following at the bottom of your Podfile,
updating the Swift version if necessary:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3' # or '3.0'
end
end
end
Realm released a new version 1.1.0. If you are using Cocoapods suggest you to check this PR and install the version 1.1.0.rc.2 to avoid the compile error Use Legacy Swift Language Version.