I'm using Vapor, and I've run into a problem where the change to Xcode 13.3 from 13.1 now means the project (without changes) will no longer build.
How can I change the version of Swift that a Vapor project will build to? Since this isn't an app, the usual convenient configuration UI isn't available, so I presume this has to be done in a configuration file, or via the terminal. Just don't know how, is all...
I think what you mean is the version of swift-tools that gets invoked rather than swift. Change the first line of Package.swift in your project's folder to use the current version needed by the latest vapor version 4:
// swift-tools-version:5.5
Then use Xcode to try to build. If this doesn't work, try Using the Clean Build Folder menu option off the Product menu and try again.
Failing this, use terminal to remove the .build folder in your project's folder and do a swift package update followed by a swift build. I know of at least one swift compiler bug that means a compile that fails with swift build will succeed with swift build -c release so it could be worth trying both.
If all this fails, include more detail in your question to show the exact cause of 'will no longer build'.
Related
So I was trying to set "custom working directory" in Xcode for my Swift package, like this
You can see I used the good old $(PROJECT_DIR) here.
But when I started to run the project, Xcode prompted me with this
So how can I make this work?
I use several pods including AlamoFire, Realm and SwiftyJSON. The pods and their code worked fine up until recently. Now None of my imports work, but gives me the error No such Module.
I have tried to use the command pod disintegrate in the terminal, then installed them again. I have linked them to the project in the general tab as well as the project phase tab.
I have tried following the steps here:
"No such module 'Alamofire'" Xcode won't recognize Alamofire framework
But step two doesn't seem to exist in the build settings and if I comment out all the imports I instead get another error:
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.
I use swift 4.1 which is verified in the build settings. I use Xcode 9.4.1 if that helps.
Very confused about this problem since everything worked fine until it suddenly stopped.
Please check your podfile if you have mentioned explicitly version for one of the dependency
For e.g
Alamofire, ~>’3.3’
Check for the compatible version for swift 4.1 if you have mentioned explicitly version for one of the pod.
Otherwise Simply remove podfile.lock and try pod update once.
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.
Select the target which uses swift
Go to Build Settings
Type Swift L in search field and scroll to Swift Language Version
Select the language version
My project built fine before updating Xcode.
Now however, I can no longer build the project. When using Swift 5, building the project just never finishes. It stops on "Building 70 of 100 tasks" and just never finishes. Those numbers aren't always the same, either, but it never finishes building.
If I try to use Xcode to convert my project from Swift 4.2 to Swift 5, it similarly never finishes converting.
If I try changing the toolchain to use the Swift 4.2.1 release toolchain, the code compiles successfully but I get this crash immediately at runtime:
dyld: Symbol not found: _$SBOWV
Referenced from: /Users/compc/Library/Developer/Xcode/DerivedData/Swift_Coder-hczsehpbafcwkfgwyameucznmhsp/Build/Products/Debug/Swift Coder.app/Contents/MacOS/../Frameworks/SavannaKit.framework/Versions/A/SavannaKit
Expected in: /usr/lib/swift/libswiftCore.dylib
in /Users/compc/Library/Developer/Xcode/DerivedData/Swift_Coder-hczsehpbafcwkfgwyameucznmhsp/Build/Products/Debug/Swift Coder.app/Contents/MacOS/../Frameworks/SavannaKit.framework/Versions/A/SavannaKit
I've tried cleaning the project and deleting derived data but neither seems to work.
The project continues to build and run perfectly fine if I use Xcode 10.1.
I had problems with some of my code involving extending the ClosedRange type to Encodable and Decodable in a custom way. In Swift 5, ClosedRange already conforms to Encodable and Decodable when its Bound is Encodable and Decodable, but the compiler wasn't giving me an error about the redundant conformance, instead just hanging on compilation.
After I modified my code to use the new Swift 5 protocol conformance, it compiled fine. It took a long time to narrow down the problem to this, however. It seems to me to be a bug in the Swift Compiler because the compiler hangs in a Playground or from the command line as well, even on a different Mac.
Do your project contains any third libraries? If so, try to figure out which one is outdated. Try to build project without this libraries, i'm perfectly sure some of them are just outdated. You may also want to set up swift language version to old one. Select the target, goto Build Settings > Swift Language Version
Please delete Derived Data,
You can go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment. Then click over the little grey arrow under Derived data section and select your project folder to delete it.
if you have Pods Than deintegrate and reinstalling all pod files again.
Hope this works for you!
Disable iCloud.
The problem was caused by discrepancies between desktop and icloud!
Spent 24h trying to find why workspace would freeze at launch.
I've been using Cocoapods to manage dependencies for my Swift project. I came across this package which is not listed at Cocoapods. Instead it suggests using Swift Package Manager. However, whenever I try to use Swift Package Manager to do basically anything, it ends up completely destroying my entire project.
So, in order to figure out how to actually use Swift Package Manager, I'm playing with it in a test project.
Here's what I've tried:
Create a new project from Xcode
File -> New -> Project -> Cocoa App
Product Name: basic-ssh-test
This creates a basic application which loads a blank window when I hit "Run". Just for fun I added print("test") to the applicationDidFinishLaunching function in my AppDelegate so the debug window says "test" when I run the program.
Now I want to add the Shout package as a dependency.
swift package init --type executable
This creates the following files:
Creating executable package: basic-ssh-test
Creating Package.swift
Creating README.md
Creating .gitignore
Creating Sources/
Creating Sources/basic-ssh-test/main.swift
Creating Tests/
Now I'm going to add the "Shout" dependency to my new Package.swift file:
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "basic-ssh-test",
dependencies: [
.package(url: "https://github.com/jakeheis/Shout", from: "0.2.0")
],
targets: [
.target(
name: "basic-ssh-test",
dependencies: ["Shout"]),
]
)
And I'll pull in the dependencies:
swift package resolve
This results in the dependencies being pulled into the .build directory:
Fetching https://github.com/jakeheis/Shout
Fetching https://github.com/jakeheis/CSSH
Fetching https://github.com/IBM-Swift/BlueSocket
Cloning https://github.com/IBM-Swift/BlueSocket
Resolving https://github.com/IBM-Swift/BlueSocket at 0.12.91
Cloning https://github.com/jakeheis/CSSH
Resolving https://github.com/jakeheis/CSSH at 1.0.3
Cloning https://github.com/jakeheis/Shout
Resolving https://github.com/jakeheis/Shout at 0.3.0
Now I regenerate the xcodeproj file:
swift package generate-xcodeproj
Now when I open the xcodeproj file there is a new group called Sources that has a single directory basic-ssh-test with a single swift file in it main.swift with print("Hello, world!").
The code that I'm actually interested in running is now in a blue folder called basic-ssh-test. All of the necessary files are still in there, but instead of running my application, Xcode is running the main.swift file. I can tell because the debug output is "Hello, world!" instead of "test".
I've read a couple of tutorials that claim that Swift Package Manager will move my source files and continue to build the same as before, but that's clearly not the case.
There's also no longer a "Main Interface" option in my Build Settings, so I can't select "MainMenu.xib" as my application starting point.
This is essentially the same thing that happens when I try to use Swift Project Manager with my existing project. It pulls in the dependencies, but it basically ignores my entire existing project and just runs the "hello world" code.
How do I use Swift Package Manager to add a dependency to an existing project without ignoring the existing codebase?
I think SPM is only compatible with Mac command line executables or libraries. This explicitly states SPM doesn't support iOS, watchOS, or tvOS platforms at all. But, since macOS AppKit/Cocoa application targets are very similar to iOS or tvOS Xcode targets, I would say this statement implies that SPM can't be used with macOS Cocoa applications out of the box either, which is what I think you're hoping for.
It looks like there is some work here on how to use it with iOS application targets which should largely translate to a macOS Cocoa target.
Until the time of this writing answer, Swift Package Manager do not support the iOS, tvOS, and watchOS. Instead, you will have to add the files from the package directly to your project.
I would suggest you creating a Dependencies group in your project and a group below that with the package name, like this answer:
So, first you will add the files dependency that you want to import into your project to the name of the package name that included in Dependencies group that we make before.
After you add the files then you can access the code as you usually would when you write it yourself like the image below. No need imports. You can see more details in here. hope it helps.
You can create a windowed application using SPM (I have a whole project sitting waiting for ABI that does this) you just need some boiler plate in swift.main. I’ll dig it out.
However the method others are suggesting is never going to work (with current versions of SPM).
However, what I am seeing is that you really want to use SPM to manage dependencies (keeping up to date etc). So I think you could do that much more easily.
Rather than creating a executable as your default target, instead create a library (perhaps call it basic-ssh-dependencies). Generate your Xcode project and drag THAT into your primary Xcode project and configure your target to to depend on it. When you update the library from SPM for changes in dependencies you should re-gen your Xcode-proj.
Let me know your mileage and any wrinkles, or if I’ve misunderstood what you are trying to achieve.
Update for XCode 11
This is A LOT easier now with XCode 11. As of this writing the current version of XCode is 11.3.1.
For an existing XCode project simply:
go to File->Swift Packages->Add Package Dependency...
enter the URL of the hosted package you want to add
choose the rules about which versions your app will use
click Finish
My general goal is to create an app, that grabs all data from the postgreSQL database. Firstly, I connected C API libpq to connect my database. Then, I found a nice wrapper around libpq to make my life easier, thanks to Perfect. To install this wrapper, I need to create Package.swift, add a dependency and regenerate my xcodeproj with swift package generate-xcodeproj.
But when I do that, the whole structure of my project is being rebuilt and, as a result, when I run the project, a simulator doesn't start and I lose understanding on what's happening and build usually fails.
New project structure
It would've been nice if somebody explained to me, what happens when I generate a project after adding Package.swift file and how to keep everything working with new packages being added.
... when I run the project, a simulator doesn't start and I lose understanding on what's happening and build usually fails.l
I suppose you already have the libpq added and working. If this is an iOS project, try just adding the PostgresSQL.swift instead of using the package.