Realm support for Swift 3.0 - ios

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.

Related

How to build Swift 3 project on Xcode 9?

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

Error compiling Swift 3.0.1 Project after Pod Update

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

Frameworks with Swift 2.3 are unable to run in Xcode 8

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

using Swift 2.2 Pods with XCode 8

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.

CocoaPods and Swift 3.0

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

Resources