Swift Packages

RSS for tag

Create 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

Xcode 16 crash trying to remove a package dependency
Feedback Submitted FB13898610 Xcode crashes with below. Pressing the "-" to remove a package dependancy. Solutions most welcome Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Termination Reason: Namespace SIGNAL, Code 6 Abort trap: 6 Terminating Process: Xcode [27376] Application Specific Information: abort() called Application Specific Signatures: NSInvalidArgumentException Application Specific Backtrace 0: 0 CoreFoundation 0x00007ff815134dc6 __exceptionPreprocess + 242 1 DVTFoundation 0x000000011257fd3e DVTFailureHintExceptionPreprocessor + 448 2 libobjc.A.dylib 0x00007ff814c24e9d objc_exception_throw + 48 3 CoreFoundation 0x00007ff81504f400 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 604 4 CoreFoundation 0x00007ff81504f18a +[NSDictionary dictionaryWithObjects:forKeys:count:] + 49 5 DevToolsCore 0x000000012118ca09 -[PBXTarget removePackageProductDependencies:] + 1053 6 DevToolsCore 0x00000001211b1c65 -[PBXTarget packageReferenceWillBeRemoved:] + 273 7 CoreFoundation 0x00007ff8150b742a -[NSArray makeObjectsPerformSelector:withObject:] + 252 8 DevToolsCore 0x000000012116200c -[PBXProject(PBXTargetedNotifications) packageReferenceWillBeRemoved:] + 267 9 DevToolsCore 0x0000000121157026 -[PBXProject removePackageReference:] + 219 10 Xcode3UI 0x0000000128db10c8 __56-[Xcode3PackageReferenceListViewController removeItems:]_block_invoke + 319 11 Xcode3UI 0x0000000128db0c7b -[Xcode3PackageReferenceListViewController removeItems:] + 1925 12 AppKit 0x00007ff81891e34d -[NSApplication(NSResponder) sendAction:to:from:] + 337 13 IDEKit 0x00000001162a8e5f __37-[IDEApplication sendAction:to:from:]_block_invoke + 315 14 DVTFoundation 0x000000011257f51d DVTInvokeWithFailureHint + 78 15 IDEKit 0x0000000116202bc0 -[IDEApplicationController application:setFailureHintMessage:duringBlock:] + 118 16 IDEKit 0x00000001162a8f2b -[IDEApplication _invokeWithFailureHint:block:] + 105 17 IDEKit 0x00000001162a8cb8 -[IDEApplication sendAction:to:from:] + 333 18 AppKit 0x00007ff81891e1c3 -[NSControl sendAction:to:] + 86 19 AppKit 0x00007ff81891e0f5 __26-[NSCell _sendActionFrom:]_block_invoke + 131 20 AppKit 0x00007ff81891dffe -[NSCell _sendActionFrom:] + 171 21 AppKit 0x00007ff81891df46 -[NSButtonCell _sendActionFrom:] + 96 22 AppKit 0x00007ff81891ae32 NSControlTrackMouse + 1823 23 AppKit 0x00007ff81891a6ef -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 125 24 AppKit 0x00007ff81891a5b6 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 666 25 AppKit 0x00007ff8189199ab -[NSControl mouseDown:] + 666 26 AppKit 0x00007ff818918353 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 4582 27 AppKit 0x00007ff818891177 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 313 28 AppKit 0x00007ff818890e23 -[NSWindow(NSEventRouting) sendEvent:] + 345 29 IDEKit 0x0000000116269d6a -[IDEWorkspaceWindow sendEvent:] + 158 30 AppKit 0x00007ff819043470 -[NSApplication(NSEventRouting) sendEvent:] + 1456 31 IDEKit 0x00000001162a8a7f -[IDEApplication sendEvent:] + 308 32 AppKit 0x00007ff818bfe8de -[NSApplication _handleEvent:] + 65 33 AppKit 0x00007ff81872209a -[NSApplication run] + 640 34 IDEKit 0x00000001162a888a -[IDEApplication run] + 54 35 AppKit 0x00007ff8186f5ff3 NSApplicationMain + 816 36 dyld 0x00007ff814c59366 start + 1942 Kernel Triage: VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x7ff814fac14a __pthread_kill + 10 1 libsystem_pthread.dylib 0x7ff814fe4ebd pthread_kill + 262 2 libsystem_c.dylib 0x7ff814f0aa79 abort + 126 3 IDEKit 0x116226509 +[IDEAssertionHandler _handleAssertionWithLogString:assertionSignature:assertionReason:extraBacktrace:] + 1178 4 IDEKit 0x1162278c3 -[IDEAssertionHandler handleUncaughtException:] + 749 5 IDEKit 0x116227c00 IDEHandleUncaughtException + 94 6 IDEKit 0x1162a9370 -[IDEApplication reportException:] + 79 7 AppKit 0x7ff818722129 -[NSApplication run] + 783 8 IDEKit 0x1162a888a -[IDEApplication run] + 54 9 AppKit 0x7ff8186f5ff3 NSApplicationMain + 816 10 dyld 0x7ff814c59366 start + 1942
0
0
37
3h
Package.resolved modified unexpectedly when switching git branches outside of Xcode
We've recently increased our use of SPM in our iOS app's Xcode project. However, we've noticed that if the Xcode project is open when we switch to a different git branch using another tool (e.g. git on the command line or in a 3rd-party GUI), the Package.resolved file is modified unexpectedly. We've received some conflicting advice about the purpose and appropriate treatment of the Package.resolved file. Some say to add it to .gitignore. On the other hand, the docs say: …be sure to commit your project’s Package.resolved file to your Git repository. This ensures a reliable CI workflow that always uses the expected version of a package dependency. For now, our workaround is to use Xcode to switch git branches, but this seems like an unusual limitation. We're on Xcode 15.3/15.4. There is discussion on the Swift Forums of potentially related problems: https://forums.swift.org/t/xcode-automatically-updating-package-resolved/41900
1
0
42
21h
The DateFormatter is returning wrong date format 2024-04-23T7:52:49.352 AMZ, 2024-05-23T11:16:24.706 a.m.Z
import Foundation let formatter = DateFormatter() let displayLocalFormat = true or false let timeZone = UTC let dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" let currentDate = Date() formatter.locale = displayLocalFormat ? Locale.current : Locale(identifier: "en_US_POSIX") formatter.dateFormat = dateFormat formatter.timeZone = timeZone formatter.string(from: date) // This function returns date format 2024-05-23T11:16:24.706 a.m.Z
4
0
142
21h
DocC not finding local sources files
Context Hello everyone, I'm a freshly graduate engineer currently learning Swift and Apple ecosystem frameworks as I wish to become an Apple Developer / Engineer. I made a very simple and light Swift package but I cannot build the documentation using DocC. Issue See my project here on github and explanations below. Behavior Building Documentation for my Swift package results in an empty page with only my Package name. Adding a documentation catalog with a start page work but only the start page is displayed after building. None of my structs in any sources files appears in the built documentation. Trying to add symbol linking to my sources files's structs in the start page (using double backquotes) results in the Topic section not built and a warning "MyStruct doesn't exist at '/MyPackage'" What I tried I found multiple information while looking for a solution, so I tried everything. None of my structs / classes have the same name as the package I did not remove the Topics section in the start page of the documentation catalog, neither I removed the Header 2 formatting. My documentation catalog and my sources files lies within MyPackage/Sources/MyPackage/ I compared my starting page and folder architecture with the Sloth demo project I did comment my structs / classes / functions with three slash /// using Xcode shortcut to pre-write documentation Technical Specifications macOS 14.5 MacBook Pro M3 Pro 18Go Xcode Version 15.4 (15F31d) swift-tools-version: 5.10 Images Conclusion I have no idea what else to do and if I am doing something wrong. Any feedback or solution on my issue would be really appreciated as I'm doing my best to learn the best practices to become an Apple developer. Thank you.
1
0
96
2d
Errors building with manual provisioning profile and packages with PrivacyInfo
Errors building with manual provisioning profile and packages with PrivacyInfo.xcprivacy added. When I look at the changes in the package, the only difference is adding this .xcprivacy file. The error looks like this: PLCrashReporter_CrashReporter does not support provisioning profiles, but provisioning profile *** has been manually specified. Set the provisioning profile value to "Automatic" in the build settings editor. Using an Enterprise certificate with manually created provisioning profile, I don't have the option to choose automatic. And I can't change build settings for the swift packages. Does anyone know how I can work around this issue?
3
0
117
1d
SPM Resolution Challenges
I've been relying on SPM to manage some packages related to a project I'm working on, and while it mostly worked well when the dependencies were small, it has become increasingly difficult to make updates to package versions and have Xcode use those updates (now around 20 total depencies). For example, suppose I have this working state: Package A (private in Github) -> tag 1.2.2 Xcode SPM 'Up to Next Major Version" -> 1.00 < 2.00 Now, I want to update package A to be a new version (e.g. 1.3.0). I update the package, give it a new tag and push the tags to git. Now, if I open my project without performing any action, the package version will almost always not update. Things I can do: 'Update Package' from the Package Dependency list. (Has no effect) 'Update to latest package versions' from the Package Dependency header. (Has no effect) Resolve package versions / Reset package caches (Has no effect) What used to work in the past was to remove the dependency in Xcode, and re-add it. 90% of the time, it wouldn't add on first try, so I would have to try to add it, cancel out of the dialog once, and try again. That used to work. Now, a new package version won't add at all. I just get the 'Unable to resolve dependencies' dialog. 'Add anyway' leaves my project in an unusable state. I'm now in a position where I have to close, clean, restart, reset caches, etc for long stretches of time until with some stroke of luck the versions update correctly and the project will build. This is hugely disruptive to my development flow and am hoping to find a reliable solution that doesn't take 30+ minutes of rebuilding and retrying before the project is in a usable state with my updated package.
0
0
137
2w
Nested xcframeworks in SPM
My organization delivers an xcframework, let's call it MyFramework.xcframework. This framework also depends on another local framework, SecondFramework.xcframework. We want to deliver the MyFramework using Swift Package Manager to our customers. The SecondFramework is embedded within MyFramework. Then the customer only needs to care about MyFramework. Our issue is that apps using our Swift Package fail to recognize the SecondFramework, displaying the message "SecondFramework module not found." Is this not possible or currently supported in SPM? Or do we need to change our approach? I appreciate any help or pointers. Thanks!
1
0
157
2w
What is the purpose of `originHash` in Package.resolved
Whenever I switch branches, Xcode seems to update the originHash field in Package.resolved. I then have to tell Xcode to manually resolve packages again. That sounds like a bug, and I can just file a bug about that. But what I want to know is… why is the originHash changing in the first place? What does that represent? Should I be committing the value that it's trying to change to? Or should I be discarding that change?
1
2
235
2w
Xcode NSMetaDataQuery error on device running IOS 17.5 - [ERROR] couldn't fetch remote operation IDs
Xcode 15.4 running on various IOS simulators and hardware devices from IOS 14.5 to 17.5. Part of my code presents a backup/restore page to the user which uses NSMetaDataQuery to update the GUI for files being uploaded or downloaded in iCloud. On every device I run the code everything works as expected EXCEPT one which is an iPhone 11 running IOS 17.5 (as of yesterday 17.5.1); there I get the following error once I start the query: [ERROR] couldn't fetch remote operation IDs: NSError: Cocoa 257 "The file couldn’t be opened because you don’t have permission to view it." "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" Due to this error I am getting no query updates and thus unable to display whether the file needs to upload, download or is synchronised. I am not initiating any upload or download of the backup file since it is placed in the ubiquitous container and I leave the up/download of the file over to IOS; all I do with the query is monitor the status of the file and take appropriate action to show the user the percentage of up/downloaded file. As said before it is only the one device causing me headaches so I don't know whether it has anything to do with IOS 17.5 that Apple have made changes that I am unaware of. I have access to an iPhone and an iPad running some version of IOS 16 and it's performing flawlessly. I have no other IOS17+ device to test on. The code runs very well on any 17.5 simulator, but we all know there are always some differences running code on a Device vs Simulator. Running 'startAccessingSecurityScopedResource()' which has been suggested by some returns 'true' on the simulator and 'false' on a device, but even then all devices work except one; so that does not seem to be the solution. Changing the query predicate has not helped either. How do I drill down to find the culprit - I'm at my wits' end. My very simple query initializer, startup & observers: (Please note, the code shown here is what's left after commenting out everything else. This was done to show that the problem really DOES lie with the Query) query = NSMetadataQuery.init() query.operationQueue = .main query.searchScopes = [NSMetadataQueryUbiquitousDocumentsScope] query.predicate = NSPredicate(format: "%K LIKE %@", NSMetadataItemFSNameKey, fileUrl.lastPathComponent) query.operationQueue?.addOperation({ [weak self] in self?.query.start() self?.query.enableUpdates() }) } func addNotificationObservers() { NotificationCenter.default.addObserver( self, selector: #selector(queryDidStart(_:)), name: .NSMetadataQueryDidStartGathering, object: query) NotificationCenter.default.addObserver( self, selector: #selector(queryGathering(_:)), name: .NSMetadataQueryGatheringProgress, object: query) NotificationCenter.default.addObserver( self, selector: #selector(queryDidUpdate(_:)), name: .NSMetadataQueryDidUpdate, object: query) NotificationCenter.default.addObserver( self, selector: #selector(queryDidFinishGathering(_:)), name: .NSMetadataQueryDidFinishGathering, object: query) }
3
0
203
2w
How to exclude RealityKitContent from Swift package for iOS?
I've created an app for visionOS that uses a custom package that includes RealityKitContent as well (as a sub-package). I now want to turn this app into a multi-platform app that also supports iOS. When I try to compile the app for this platform, I get this error message: Building for 'iphoneos', but realitytool only supports [xros, xrsimulator] Thus, I want to exclude the RealityKitContent from my package for iOS, but I don't really know how. The Apple docs are pretty complicated, and ChatGPT did only give me solutions that did not work at all. I also tried to post this on the Swift forum, but no-one could help me there either - so I am trying my luck here. Here is my Package.swift file: // swift-tools-version: 5.10 import PackageDescription let package = Package( name: "Overlays", platforms: [ .iOS(.v17), .visionOS(.v1) ], products: [ .library( name: "Overlays", targets: ["Overlays"]), ], dependencies: [ .package( path: "../BackendServices" ), .package( path: "../MeteorDDP" ), .package( path: "Packages/OverlaysRealityKitContent" ), ], targets: [ .target( name: "Overlays", dependencies: ["BackendServices", "MeteorDDP", "OverlaysRealityKitContent"] ), .testTarget( name: "OverlaysTests", dependencies: ["Overlays"]), ] ) Based on a recommendation in the Swift forum, I also tried this: dependencies: [ ... .package( name: "OverlaysRealityKitContent", path: "Packages/OverlaysRealityKitContent" ), ], targets: [ .target( name: "Overlays", dependencies: [ "BackendServices", "MeteorDDP", .product(name: "OverlaysRealityKitContent", package: "OverlaysRealityKitContent", condition: .when(platforms: [.visionOS])) ] ), ... ] but this won't work either. The problem seems to be that the package is listed under dependencies, which makes the realitytool kick in. Is there a way to avoid this? I definitely need the RealityKitContent package being part of the Overlay package, since the latter depends on the content (on visionOS). And I would not want to split the package up in two parts (one for iOS and one for visionOS), if possible.
1
0
265
2d
Weird Swift overriding cocoapods
I don't even use Swift. I use Flutter. I am getting this odd always_embed_swift library warning that seems to be overriding my runner target on xcode. I'll just attach the image down below of what I'm dealing with. Please an apple engineer or someone just help me because this has been a struggle lol. I need to change this but can't find the setting to do so.
0
0
170
3w
How might I get didSet behaviour on an AppStorage var?
I've defined a value stored in UserDefaults. In a view struct I have code that can successfully update the stored value. I've also added an @AppStorage var in an instance of a class, that can read this value and run business logic that depends on the current stored value. But what I really want to do, is have code in my class that gets automatically called when the value stored in UserDefaults gets updated. Basically I want to do this: @AppStorage("languageChoice") var languageChoice: LanguageChoice = .all { didSet { print("hello") } } Unfortunately didSet closures in @AppStorage vars do not appear to get called :-( My clumsy attempts to use combine have all ended in tears from the compiler. Any/all suggestions are greatly appreciated. thanks, Mike
3
0
230
1w
xcodebuild -resolvePackageDependencies stopped working after Mac Os update
My config is as follow MacBook Pro with M3 Pro and Sonoma 14.5 OS XCode 15.2 Build version 15C500b swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5) Target: arm64-apple-macosx14.0 Darwin lonwx2049951 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030 arm64 I am behind corp proxy and have quite limited privileges to install or use any tools/commands requiring admin privileges. The App itself plus a few company submodules are hosted on Azure Devops and this side works as usual. The App also uses a few dependencies hosted on GitHub and that need to be resolve every time I'm switching/creating new branches Until Monday I was using following terminal command to do so xcodebuild -resolvePackageDependencies -scmProvider system However, on Monday when I tried the above I was presented with error on each of the dependencies, see attached depenedencies_error.txt The only change that happen was the Mac OS update on Monday morning when I turn on my Mac from 14.4 to 14.5 Is it possible that this update removed some of the settings? I have tried the following: deleting DerivedData folder, cleaning and rebuilding project cloning the dependencies manually adding PAT token using SSH for fetching deleting Package.resolved file cloning project from Azure repo into different location Any suggestions will be appreciated.
1
0
218
3w
Xcode 15.4 - Missing package product "<package name>"
Hello, I'm having this issue that Xcode tells me it cannot find the Swift Packages I'm using within my App. When I first open Xcode, all the Package Dependencies are listed correctly in my project navigator. Also, building the app for the first time runs without any issues. But right after the first build is finished, the Package Dependencies are not listed any more and the build fails, telling me that all the packages are missing. I have to manually click on File -> Packages -> Reset Package Caches, after that it works again. But only for exactly one build. I basically have to do this step for every single build. I found out that there is this Package.resolved file which lists all the used packages with their respective version and some kind of hash. This file is located inside the .xcodeproj file, in my case it's this location: MyApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved This file is deleted after the successful build. And I think that's the reason why all of a sudden Xcode screams that the packages are missing. After resetting the package caches this file re-appears. But it seems it has to be regenerated every single time. This bug is VERY annoying and exists already since the last view versions of Xcode, not just the latest one. I was hoping this bug is fixed at some point. Current Xcode version: 15.4 (15F31d) MacBook Air 13", M3, 2024 running macOS Sonoma 14.5 Just in case, my Package.resolved file is attached below. Package.resolved
1
2
447
3w
SwiftUI Preview - Undefined symbols for architecture arm64
Starting on Xcode 15.3 and 15.4 my SwiftUI Previews stopped working with the following error: == PREVIEW UPDATE ERROR:     LinkDylibError: Failed to build ContentView.swift          Linking failed: linker command failed with exit code 1 (use -v to see invocation)          ld: warning: search path '/Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator' not found     Undefined symbols for architecture arm64:       "static MyLibrary.DisplayUtil.getText() -> Swift.String", referenced from:           closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o       "type metadata accessor for MyLibrary.DisplayUtil", referenced from:           closure #1 () -> SwiftUI.Text in (extension in Demo_Broken_Preview_PreviewReplacement_ContentView_1):Demo_Broken_Preview.ContentView.(__preview__body in _1BA320C8FB5388C953E1E463345C3D72).getter : some in ContentView.1.preview-thunk.o     ld: symbol(s) not found for architecture arm64     clang: error: linker command failed with exit code 1 (use -v to see invocation) After much trial and error, I narrowed it down to my SwiftUI views using properties or functions inside components in Swift Packages. This is a simple example of my Swift Package: public class DisplayUtil {     public func getText() -> String {         return "Text"     }          public static func getText() -> String {         return "Text"     } } And my SwiftUI View import SwiftUI import MyLibrary struct ContentView: View {     var body: some View {         VStack {             Text(DisplayUtil.getText())         }         .padding()     } } #Preview {     ContentView() } The same code works fine on Xcode 15.2 Link to the sample project: https://www.icloud.com/iclouddrive/0c00AD0esi2PwqqiRggokfwGw#Demo%5FBroken%5FPreview Is anybody else having a similar issue?
1
0
341
4w
Swift Package not able to add into the project
Hi There, I have a strange problem: the Swift package cannot be added to my iOS project. The problem might be due to the project settings, but despite trying for a long time, I still haven't been able to figure it out. My project is a React Native project and uses CocoaPods. When I drop the Swift package into my React Native project, the package becomes a folder. When I drop the Swift package into other iOS projects, it works without any problems. If I try to use "Package Dependencies" to add the Swift package, it gets stuck on "Preparing to validate..." My project seems unable to add any Swift packages; it cannot add other Swift packages either. The Swift package is local. However, it works fine in other projects, even in newly created React Native projects. The problem might be with my project itself, but I have no idea where to check now. please guide me with any advice, I will appreciate it!
0
0
162
May ’24