How to build Realm using Swift 2.3? - swift

I have already change toolchain to swift 2.3 by
export PATH=/Applications/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/bin:"${PATH}"
And did
Open the Xcode project -> Click on the Realm project -> RealmSwift target -> 'Build Settings' tab -> set Use Legacy Swift Language Version to Yes (if building for Swift 2.3) or No (if building for Swift 3).
as Build realm for Swift 3 & Xcode 8 says.
But what I get is still swift 3.0 version.
Any idea?
I looked into build.sh and found out the export path doesn't work as in xcrun swift, which was used by realm to get swift version, it was still 2.2 or 3.0, depending which toolchain was used.

To build Realm from the master branch with Swift 2.3, set the REALM_SWIFT_VERSION environment variable to 2.3 when building. For instance, to build for OS X:
REALM_SWIFT_VERSION=2.3 sh build.sh osx
Realm's build scripts will determine which Xcode version to use based on the value of the REALM_SWIFT_VERSION environment variable, so there's no need to modify your PATH variable.

I have chosen #bdash answer as the best one. However, if you want to keep using swift 2.3 in command line. You can do
export TOOLCHAINS=com.apple.dt.toolchain.Swift_2_3
then use
sh build.sh osx-swift
#bdash answer only affects realm. So I think it is better than mine. My answer is inspired by Keith Smiley, who pointed out that I could use
xcrun --toolchain "com.apple.dt.toolchain.Swift_2_3" swiftc -v
to get 2.3 works.
the toolchain info is in /Applications/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/ToolchainInfo.plist

Related

Can not import TensorFlow for Swift in Xcode Playground

I'm trying to use Swift for TensorFlow and have followed the directions found here: https://github.com/tensorflow/swift/blob/master/Installation.md
When I go ahead and import TensorFlow as such within a Swift Playground file:
import TensorFlow
I get this error: "The active toolchain is not compatible with playgrounds. libswiftCore.dylib could not be loaded"
I was able to use Swift for TensorFlow within the REPL so I know it should work. Anyone have any ideas as to how to fix this issue? It clearly works as shown in this demonstration: https://www.youtube.com/watch?time_continue=819&v=Yze693W4MaU
Get the latest stable toolchain (e.g. v 0.6), install it, then go to Xcode > File > New > Project > Macos - Command Line Tools (instead of Playground). Additionally, the December 23, 2019 development toolchain—and beyond—should not require switching to the Legacy Build System. More information in this discussion here.
Was running into this as well. Answered in the Google Group - turns out you need to make sure you are creating a macOS playground and not an iOS playground.
I had the same issue and it turns out is the playground type.
From the Google Group reply:
As a synthesis of answers above and my own experience now with the latest May 8, 2020 builds and comments from the Google Group, I find:
SUCCESS
Xcode Project Command-line (as #8bitmp3 answered above)
Command-line swiftc (using the -O argument. Note this is the compiler)
FAILURE
Xcode Playground macOS (as #ian-do originally asked)
Command-line swift (and confirmed by Google Group. Note this is the interpreter)
For those interested in the command-line success (macOS 10.15.4), install the toolchain from here, create the source code file inference.swift per this page, and execute the following:
# Test this command. Expected outcome is your existing Xcode app as show below
$ xcrun -f swift
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
# Switch to the new TensorFlow toolchain you installed
# Mine was located at /Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.9.xctoolchain/
# Open the Info.plist file, locate CFBundleIdentifier, and copy the string value
# Mine was com.google.swift.20200507
$ export TOOLCHAINS=com.google.swift.20200507
# Test the switch to your TensorFlow toolchain. Note the different result
$ xcrun -f swift
/Library/Developer/Toolchains/swift-tensorflow-RELEASE-0.9.xctoolchain/usr/bin/swift
# Compile your Swift for TensorFlow source code
$ cd <directory with .swift file>
$ swiftc -O -sdk `xcrun --show-sdk-path` inference.swift
# Run the program
$ ./inference
[[0.68070436]]

Swift 3.1.1 compile error: unknown key 'SwiftImportAsNonGeneric'

Some time after upgrading to Xcode 9, I discovered that I was no longer able to build a Kitura-based project with the Swift 3.1.1 snapshot (which I have installed via swiftenv).
When I ran swift build, some time into the build I would get:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.apinotes:8:28: error: unknown key 'SwiftImportAsNonGeneric'
SwiftImportAsNonGeneric: true
^
<unknown>:0: error: could not build Objective-C module 'Foundation'
It seems that there is a dependency between Swift and Xcode, and Xcode 9 is no longer fully compatible with Swift 3.1.1 (or earlier) snapshots. I believe it may be because my project uses Foundation, and Foundation on Mac is provided as part of Xcode, whereas on Linux it is part of the Swift snapshot (via swift-corelibs-foundation).
I did find a solution to this problem: If I keep a copy of Xcode 8.3.3 around (eg. in /Applications/Xcode8.3.3.app) then I can use sudo xcode-select -s /Applications/Xcode<version>.app/Contents/Developer to select the appropriate one prior to building with SPM, and I can then build both Swift 3.1.1 and 4.0 projects on the same system.
However, this feels a bit clunky. Each time I build a project with the 'other' Swift version, I have to make sure I run xcode-select, or the build will fail. Is having multiple versions of Xcode the right solution in this case, or am I missing a trick with Xcode 9?
note that if, like me, you upgraded Xcode via the App Store, previous versions of Xcode are still available from https://developer.apple.com/download/more/

Module compiled with swift 3.0 cannot be imported in Swift 3.0.1

I upgraded Xcode to 8.1 GM and am now getting the below error for SwiftyJSON. Other imported frameworks seem to work. Is there a way to force this to work in Swift 3 until SwiftyJSON upgrades their framework? I used Carthage to import/update frameworks. I also tried changing Use Legacy Swift language version On and Off to no avail.
Module compiled with Swift 3.0 cannot be imported in Swift 3.0.1:
Modules/SwiftyJSON.swiftmodule/arm64.swiftmodule
SwiftyJson is being downloaded precompiled by carthage. The precompiled download is with Swift Version 3.0. That makes the compiler complain that the version is not correct. Using the following command:
carthage update --platform iOS --no-use-binaries
SwiftyJson (and all other frameworks within Carthage) will be compiled locally using the local version of Swift (3.0.1) and the compiler will not complain anymore.
Remove the app chache from DerivedData, and rebuild. the error may be fixed.
The DerivedData path like this:
~/Library/Developer/Xcode/DerivedData/
Make sure you've placed the new XCode 8.1 GM package in your Applications folder. We ran into this issue when one of us was running Carthage to update our dependencies, but had not replaced the XCode old 8.0 application in the applications folder (8.1 GM was running off the Desktop).
You want to make sure that when you run the following in terminal: xcrun swift -version that it returns Apple Swift version 3.0.1.
Updating default Xcode to new one on terminal worked for me.
Step 1 : Use following command to update Xcode version to latest on Terminal. Ref
sudo xcode-select -switch <path/to/>Xcode.app
Step 2 : Now try carthage update command
carthage update --platform iOS
Just to give the latest updates:
Carthage has released version 0.20 on Feb 27, 2017.
Carthage now only uses the pre-build binary if available pre-build binary is compatible.
That is being said, you no longer have to use: --no-use-binaries to avoid incompatible pre-build framework.
So make sure that you have carthage version greater than 0.20 and simply do:
carthage update --platform iOS
Just like #zirinisp said:
You can Using the following command:carthage update --platform iOS --no-use-binaries
Using the following command:xcrun swift -version to see the Swift version
Do this: Xcode->preferences->locations to clear the derived data and archives data, the most important to change the command line tools to "Xcode 8.1"
Using the following command:xcrun swift -version,you can see the swift version is 3.0.1
Set Use Legacy Swift Language Version = NO
I hope it will help you
Move the beta/GM version if the Xcode to /Applications folder and name it Xcode-beta
Check the output of:
xcrun swift --version
by running this command in terminal, its output should match with the swift version you want the app to compile, because Carthage uses output of this command, to determine the local Swift version.
Update Xcode version to latest on Terminal by running following command:
sudo xcode-select -s /Applications/Xcode-beta.app/
Build the libraries for iOS and prevents Carthage from downloading existing (yet incompatible) precompiled binaries, by running following command:
carthage update --platform iOS --no-use-binaries
Clean & Build
I had exactly the same issue with the library XCTest_Gherkin, what it worked for me was:
Product -> Scheme -> XCTest-Gherkin
Product -> Build
Hope it helps. I am using Cocoapods.
In Xcode Build Settings make sure your Framework Search Paths contain the appropriate Carthage Build folder:
$(inherited)
$(PROJECT_DIR)/Carthage/Build/iOS

Trouble getting Vapor to work with Xcode 8 beta 3

I was following the instructions here, but was not able to get vapor working on my mac. Here're my xcode and swift versions
Xcode 8.0
Build version 8S174q
Apple Swift version 3.0-dev (LLVM 8fcf602916, Clang cf0a734990, Swift 000d413a62)
Target: x86_64-apple-macosx10.9
When I try to install the toolbox using this command
curl -sL toolbox.qutheory.io | bash
The installation is unsuccessful and yields this message
⚠️ It looks like your Command Line Tools version is incorrect.
Make sure Xcode > Preferences > Locations > Command Line Tools is set correctly.
Correct: Xcode 8.0 (8S162m)
Current: Xcode 8.0
Build version 8S174q
⚠️ It looks like your Swift install location has been modified.
Correct: /usr/bin/swift
Current: /Users/<name>/.swiftenv/shims/swift
❌ Incompatible
Reason: Invalid Swift version
Output must contain 'swiftlang-800.0.33.1'
Current 'swift -version' output:
Apple Swift version 3.0-dev (LLVM 8fcf602916, Clang cf0a734990, Swift 000d413a62) Target: x86_64-apple-macosx10.9
📖 Visit our docs for step-by-step instructions on installing Swift correctly.
http://docs.qutheory.io
👋 or Join our Slack and we'll help you get setup.
http://slack.qutheory.io
From this, I can gather that my swift location is wrong (I don't remember changing it) and that my xcode build number is wrong (because xcode beta 2 is no longer available for download, so I got xcode beta 3.)
Can anybody help me to get this working without changing too much, or is this framework still too finicky to work with a slightly different setup?
Unfortunately it's impossible to create packages that work between different Swift 3 development previews because of how much changes in each preview. Things that compiled today might not compile tomorrow and there is no way to selectively target a given preview in code.
Because of this, the Swift version declared in https://github.com/qutheory/vapor#-current-environment for a given Vapor version must be the one used.
Vapor 0.14 relied on the Swift 3.0 preview 2 version that comes with Xcode 8 beta 2. There is currently no way to download Xcode 8 beta 2 now that Apple has stopped hosting it upon the release of Xcode 8 beta 3. That was an oversight.
Vapor 0.15 will not rely on Xcode 8 beta previews and should be released in a few days.
Open Xcode and make sure the correct SDK is selected:
👀 Xcode > Preferences > Locations > Command Line Tools
Select XCode 8
Then continue with the tutorial you are following.

Swift Package Manager Not Installing

So if you navigate here, you'll find instructions saying that the package manager is bundled in the downloads on this page.
It says that I can check with:
swift build --help
But my only output has been:
:0: error: no such file or directory: 'build'
I have downloaded both installation packages and installed them. I can see that the toolchains are installed here. (I also installed the previous version out of desperation).
The instructions aren't very explicit and in a world of all in one IDE's, I haven't yet experienced installing a language of my own in this way. Is there something obvious I'm missing in the process?
Do you have the PATH environment variable setup to map to the correct Swift?
swift --version should show
Apple Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c)
Target: x86_64-apple-macosx10.9
If you are running a Swift version prior to 2.2, then you need to set your path to the new toolchain installed by the Swift 2.2 snapshot. This can be done by editing your .bash_profile and adding
export PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin:$PATH
as the last line and then source ~/.bash_profile to update your settings.
Edit
On December 10, 2015 there was a new snapshot released. --version still shows 2.2-dev but shows updated (SHA-1?) hashes.
Apple Swift version 2.2-dev (LLVM 7bae82deaa, Clang 53d04af5ce, Swift 5995ef2acd)
Target: x86_64-apple-macosx10.9
These releases are also tagged at the individual project level as a release: https://github.com/apple/swift/releases