I have a project that imports SPM swift-navigation which in-turn imports SPM https://github.com/pointfreeco/swift-perception
I have a test target it builds and runs with no issues in XCode however if I run with xcodebuild i get the below error (I have done basics removed derived data etc.)
❌ error: Build input file cannot be found: '/Users/chris/mtp-iOS-retail-iPhone/build/Build/Products/Debug/PerceptionMacros'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? (in target 'Perception' from project 'swift-perception')
How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here
Swift Packages
RSS for tagCreate reusable code, organize it in a lightweight way, and share it across Xcode projects and with other developers using Swift Packages.
Posts under Swift Packages tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi everyone,
I've been struggling for a few weeks to integrate my Core ML Image Classifier model into my .swiftpm project, and I’m hoping someone can help.
Here’s what I’ve done so far:
I converted my .mlmodel file to .mlmodelc manually via the terminal.
In my Package.swift file, I tried both "copy" and "process" options for the resource.
The issues I’m facing:
When using "process", Xcode gives me the error:
"multiple resources named 'coremldata.bin' in target 'AppModule'."
When using "copy", the app runs, but the model doesn’t work, and the terminal shows:
"A valid manifest does not exist at path: .../Manifest.json."
I even tried creating a Manifest.json manually to test, but this led to more errors, such as:
"File format version must be in the form of major.minor.patch."
"Failed to look up root model."
To check if the problem was specific to my model, I tested other Core ML models in the same setup, but none of them worked either.
I feel stuck and unsure of how to resolve these issues. Any guidance or suggestions would be greatly appreciated. Thanks in advance! :)
Topic:
Machine Learning & AI
SubTopic:
Core ML
Tags:
Swift Packages
Swift Student Challenge
Swift Playground
Core ML
Hey everyone!
I’m encountering an issue while attempting to animate height changes of the content inside safeAreaInset(edge:alignment:spacing:content:).
When animating a reduction in the frame height, the container view (in my case, Map) also animates unexpectedly.
However, when animating an increase in the frame height, the animation works smoothly, and the Map view remains still.
How can I address this odd resizing behavior of the container?
Code:
struct MapView: View {
var body: some View {
Map()
.safeAreaInset(edge: .bottom) {
MapDetailView()
}
}
}
struct MapDetailView: View {
@State private var oldHeightOffset: CGFloat = 0
@State private var newHeightOffset: CGFloat = 0
@State private var containerHeight: CGFloat = 0
private var drag: some Gesture {
DragGesture(coordinateSpace: .global)
.onChanged { value in
withAnimation(.interactiveSpring) {
newHeightOffset = oldHeightOffset + value.translation.height
}
}
.onEnded { value in
switch newHeightOffset {
case containerHeight * 0.625...containerHeight:
withAnimation(.spring) {
newHeightOffset = containerHeight * 0.75
}
case containerHeight * 0.25..<containerHeight * 0.625:
withAnimation(.spring) {
newHeightOffset = containerHeight * 0.5
}
case 0..<containerHeight * 0.25:
withAnimation(.spring) {
newHeightOffset = 0
}
default:
break
}
oldHeightOffset = newHeightOffset
}
}
var body: some View {
NavigationStack {
Rectangle()
.fill(.clear)
.containerBackground(.ultraThinMaterial, for: .navigation)
}
.gesture(drag)
.containerRelativeFrame(.vertical) { length, _ in
length - newHeightOffset
}
.onGeometryChange(for: CGFloat.self) { geometryProxy in
let frame = geometryProxy.frame(in: .local)
return frame.height + newHeightOffset
} action: { containerHeight in
self.containerHeight = containerHeight
}
}
}
Reducing safe area inset's content height (drag down):
Increasing safe area inset's content height (drag up):
When I run a mixed OC and SWFit project, systems running before iOS 18 will experience the following crashes
在Mac OS 15.2 使用 Xcode 16.2 构建项目时,我遇到了以下错误:
Showing All Errors Only
Prepare packages
Prepare build
Build service could not create build operation: unable to load transferred PIF: The workspace contains multiple references with the same GUID 'PACKAGE:1Y9CU7L2QFO7OX4UJBYP19ZPPL5MJNV3R::MAINGROUP'
Activity Log Complete 2024/12/24, 15:26 0.2 seconds
When I run a mixed OC and SWFit project, systems running before iOS 18 will experience the following crashes
I'm a new app developer and am trying to add a button that adds pictures from the photo library AND camera. I added the first function (adding pictures from the photo library) using the new-ish photoPicker, but I can't find a way to do the same thing for the camera. Should I just tough it out and use the UI View Controller struct that I've seen in all of the YouTube tutorials I've come across?
I also want the user to be able to crop the picture in the app after they take a picture.
Thanks in advance
On a ScrollView+LazyVStack, the addition of .scrollTargetLayout causes many list items to be initialized, instead of the ordinary economical behavior of LazyVStack, where only the necessary items and views are initialized. Even worse, as the stack is scrolled down, all list items are reinitialized for every small scroll.
Without, .scrollTargetLayout, everything works fine.
I've tried every variation of locating modifiers, and different ways of identifying the list items, with no success.
Any ideas? Thanks.
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \Post.created, ascending: true)],
animation: .default)
private var posts: FetchedResults<Post>
var body: some View {
ZStack{
ScrollView{
LazyVStack(spacing:0) {
ForEach(posts, id: \.self) { post in
PostView(post: post)
}
.onDelete(perform: deletePosts)
}.scrollTargetLayout() // <---- causes multiple Posts re-instantiations for any small scroll, very slow
}
.scrollPosition(id: $scrolledID)
.scrollTargetBehavior(.paging)
I'm adding Admob ads to my app, and Admob needs to know the width of the view, so I'm using GeometryReader for that. To prevent GeometryReader from grabbing screen space, I've wrapped the main view in GeometryReader { }. I then use geometry.size.width in my call to the adView.
This all works fine. I have two main screens where I show ads, and they both work, until I rotate the device. Then the app crashes!
If I comment out the GeometryReader code and pass a fixed value to the ad view, I can rotate the device with no fear of a crash.
My question is: Do I have to accept that GeometryReader will crash the app when it's rotated, or is there another, stable way to get view dimensions?
Setup
I have 2 swift packages and I try to use stirng catalog to manage your localizations
I would like to use some specific keys in these packages and some common ones (e.g. "ok_button_tittle")
Problem statement
I really don't like the idea of creating separate (but the same) translations in these packages
I have tried using something like
String(
localized: "ok_button_title",
table: "Localizable",
bundle: .main,
comment: "Ok button title"
)
This does use translations from the main bundle, however this does not automatically create the keys in string catalog
Question
Is there any possibility to reuse the translations from the main bundle?
Maybe there is a hack to make the keys appear automatically in the correct bundle? Or is it a bug?
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Swift Packages
Swift
Asset Catalog
Localization
I am writing a package in Swift using Xcode 16.1 (swift-tools-version: 6.0) and am trying to use features that became available in later versions of macOS and iOS.
The following line naturally causes a compiler error when compiling against 'My Mac':
let match = "test-string".firstMatch(of: /-(.+)/)!
'firstMatch(of:)' is only available in macOS 13.0 or newer
I can of course fix this by using @available(macOS 13.0, *), but there are dozens of methods and I would prefer to use the platforms property in the Package file like this:
platforms: [
.macOS(.v10_13),
.iOS(.v16)
],
However for reason that are not clear, this does not work and the compiler errors remain.
I have tried cleaning, removing derived data etc.
What I am doing wrong?
We have a dependency, Apollo iOS, that is managed by SwiftPM in an internal module Swift Package.
That internal Swift Package is then linked and included in our iOS target.
The iOS target has an associated WidgetKit extension app.
When archiving the app, we're seeing extremely long "Copy Apollo_Apollo.bundle" build steps, on the magnitude of 15 minutes. This is only happening when copying the bundle for the Widget extension app.
Builds are done with Xcode 15.2, but we've tried on 15.4 and 16.2, seeing a few minutes shaved off.
How can we begin to debug this issue?
This is probably a beginner's mistake, but I can't find anything about this error anywhere, and it's completely reproducible, even on GitHub Runners and with a fresh Xcode project.
The error doesn't seem to be caused by the Swift package used, Defaults, but by xcodebuild.
macOS Sequoia 15.2 (24C101)
Xcode Version 16.2 (16C5032a)
Defaults Version 9.0.0
When following Defaults' installation instructions, building and archiving from Xcode still works fine, but building with xcodebuild always fails with this error:
Copy /Users/user/DefaultsTest/build/Release/DefaultsTest.app/Contents/Resources/Defaults_Defaults.bundle /Users/user/DefaultsTest/build/Release/Defaults_Defaults.bundle (in target 'DefaultsTest' from project 'DefaultsTest')
cd /Users/user/DefaultsTest
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks /Users/user/DefaultsTest/build/Release/Defaults_Defaults.bundle /Users/user/DefaultsTest/build/Release/DefaultsTest.app/Contents/Resources
error: /Users/user/DefaultsTest/build/Release/Defaults_Defaults.bundle: No such file or directory (in target 'DefaultsTest' from project 'DefaultsTest')
I made a fresh, reproducible Xcode project here:
https://github.com/F1248/DefaultsTest
And a failing GitHub Action here:
https://github.com/F1248/DefaultsTest/actions/runs/12303972248/job/34340347771
Any help would be greatly appreciated.
We have a tool in our CI which periodically updates our iOS project's Swift Package Manager dependencies. The script that does a few things, but generally speaking it
first removes the existing package.resolved at
./ProjectName.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
and then runs:
xcodebuild -resolvePackageDependencies -disablePackageRepositoryCache
This regenerated the package.resolved file to reflect the latest, updated versions of the dependencies. It is the equivalent of doing Xcode > File > Packages> Update to Latest Package Versions.
This has been working perfectly for a long time, but has stopped working since we moved from Xcode 15.4 to Xcode 16. I have also tested this with Xcode 16.1 and 16.2 - with no luck.
I have tried running this command locally, and can confirm it is not an issue with the environment of our CI. I have also tried swift package update.
Both of these commands appear to work - no errors are thrown, and the logs say "resolved source packages". However, they are not updating the packages. They are making no changes to the package.resolved file.
However, using Xcode > File > Packages> Update to Latest Package Versions in Xcode 16 works as expected - the packages are updated and the .resolved file is updated.
Is there now a different way to update Swift packages via the command line, or is this likely an Xcode 16 bug?
Update: This feels broken, so I have submitted a Feedback Report (FB16108036) but perhaps someone can suggest a workaround for the time being!
Let's say I have a local package Foo, Bar and Baz.
Foo has Bar and Baz as dependency and has test target,FooTests.
Below is the Package.swift manifest that describes package Foo.
import PackageDescription
let packages: [Package.Dependency] = [
.package(path: "../Bar"),
.package(path: "../Baz"),
]
let products: [Target.Dependency] = [
.product(name: "Bar", package: "Bar"),
.product(name: "Baz", package: "Baz"),
]
let package = Package(
name: "Foo",
platforms: [
.iOS(.v16),
],
products: [
.library(
name: "Foo",
targets: ["Foo"]
),
],
dependencies: packages,
targets: [
.target(
name: "Foo",
dependencies: products,
path: "Sources"
),
.testTarget(
name: "FooTests",
dependencies: [.target(name: "Foo")],
path: "Tests",
swiftSettings: swiftSettings
),
]
)
Bar and Baz is also local packages.
Due to the limitations of the project, Baz has sources with symbolic links instead of exact directories, and these sources are what FooTests will test.
If I run FooTests, test succeed with proper logs indicating that all test methods are run correctly, but test coverage says that Baz's coverage is 0% and there is no executable lines unlike the Bar which is not what be tested.
Is there any way to fix this problem?
Hello,
I have integrated LZMA2 compression into my iOS app, Hogs, and successfully implemented compression. However, when attempting to upload the app for TestFlight, I encountered an error:
"The app references non-public symbols in Payload/Hogs.app/Hogs: _lzma_code, _lzma_end."
These functions are part of the LZMA compression library (specifically LZMA2). Here's a detailed description of the issue:
What I Have Done:
LZMA2 Integration: I integrated LZMA2 compression into the app and created a wrapper around the LZMA functions (_lzma_code, _lzma_end) to prevent direct references.
App Build Configuration:
I ensured the LZMA2 library is linked correctly with the -lzma flag in the linker settings.
I wrapped the LZMA functions in custom functions (my_lzma_code, my_lzma_end) in an attempt to avoid using the non-public symbols directly.
Error Message:
During the app submission process, I received the following error:
"The app references non-public symbols in Payload/Hogs.app/Hogs: _lzma_code, _lzma_end."
Steps Taken to Resolve:
Checked if any LZMA functions were exposed incorrectly.
Ensured that all non-public symbols were properly encapsulated in a wrapper.
Verified linker settings to ensure the proper inclusion of the LZMA2 library.
Request:
Could anyone provide suggestions or best practices to resolve this issue and avoid references to non-public symbols? Should I use a different method for linking LZMA2 or encapsulating these symbols?
Thank You:
I appreciate your help in resolving this issue so I can move forward with submitting the app for TestFlight.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
Swift Packages
Apple Archive
Compression
TestFlight
Pretty sure this is a no-no, but asking just in case there's an easy way to make this work
struct DocumentContentView: View {
private static let logger = Logger(
subsystem: "mySubsystem",
category: String(describing: Self.self)
)
var body: some View {
VStack {
Text("Hello")
logger.trace("hello")
}
}
}
This code generates the following compile error at the logger.trace line
buildExpression is unavailable: this expression does not conform to View
I suspect every line of the body var (or any @ViewBuilder - designated code?) needs to 'return' a View. Is this correct? or more importantly any work arounds other than putting some/all of the view contents in a. func()?
Hi folks,
I've been having this issue for the last few months, where Xcode Cloud fails to resolve Swift package dependencies while compiling my builds, seemingly at random.
Some of my Xcode Cloud builds will fail after several minutes, with an error log looking like that :
xcodebuild: error: Could not resolve package dependencies: failed downloading 'https://dl.google.com/firebase/ios/bin/grpc/1.62.2/rc0/grpcpp.zip' which is required by binary target 'grpcpp': downloadError("The request timed out.")
Whenever this happens, I have to manually restart an Xcode Cloud build process (or several builds, since the error can happen multiple times in a row), to the point it's becoming increasingly painful to rely on Xcode Cloud for my workflow.
The failing packages are mostly random (meaning, it's not always the same one that Xcode fails to resolve), but they are always publicly accessible, even though I have an environment variable set in my Xcode workflows to retrieve a single Github private dependency (maybe this has some kind of importance).
Could anyone tell me if this is an isolated issue, or if I could do anything on my end to resolve this ?
Thank you !
Topic:
Developer Tools & Services
SubTopic:
Xcode Cloud
Tags:
Swift Packages
Continuous Integration
Xcode Cloud
I'm making an app using SwiftUI and trying to use the TextEditor view. However when I run it, and I try entering text into the TextEditor, the characters don't appear, they do however appear in the terminal that i used to run the app. The same problem exists with the TextField view.
I usually run it using swift run but have also tried swift build and running the produced executable as well as using release mode.
Minimal example:
import SwiftUI
@main
struct Example: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State var text: String = ""
var body: some View {
TextEditor(text: $text)
}
}
Issue Description
I'm have Local Swift Package which contains binary target to private github releases
url is formed like below:
https://api.github.com/repo/{owner}/{repo}/releases/assets/{asset_id}.zip
I register the private repo to the xcodecloud, but still xcodecloud does not recognize "api.github.com" domain. So build keeps fails at downloading binary artifact.
https://github.com/{owner}/{repo}/releases/download/{tag}/Myframework.xcframework.zip is not a valid choice since this kind of url, is not supported for private repository.
Proposed Solution
Please add authorization to the "api.github.com" like normal "github.com".