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.

Swift Packages Documentation

Posts under Swift Packages tag

199 Posts
Sort by:
Post not yet marked as solved
0 Replies
24 Views
Hello, we've been working with the Swift Chart framework, and the BarMark chart has a memory problem/bug when using it on the iPhone with iOS 16.0 Developer Beta 3. Problem When using the BarMark chart on the simulator with fake values, the chart load, however if we try to load the data on the iPhone, the code breaks with this error: Thread 1: EXC_BAD_ACCESS (code=2, address=0x16d153ff8). This however does not happen when we change the chart type from BarMark to LineMark. Then all of the sudden, the chart loads on the iPhone. Now, when the error hits, Xcode show that the memory usage is extremely high. Working Code High Memory usage and error
Posted Last updated
.
Post not yet marked as solved
3 Replies
522 Views
We are working behind proxy and I have set the git proxy by git config --global http.proxy http://xxxxx and make sure the git can work properly. But when I am trying to use SPM to add the pakcages, it always show the "AN unknown error occured. unexpected return value from ssl handshake -9896(-1)". Reproduce step: create the Mac app project File --> Add packages... Copy the "https://github.com/daltoniam/Starscream" into serach area Also I have checked the developer forums and find this issue has been existed for long time, Is there any upate on this issue? Thanks in advance.
Posted
by kern.zhou.
Last updated
.
Post marked as solved
2 Replies
242 Views
For WWDC22 session "Meet Swift Package plugins " the following code snipped is shared in Apple's Developer application: In Xcode 14 Beta 1 I receive the compilation error Cannot find type 'XcodeBuildToolPlugin' in scope Is the given example valid and is a struct/type missing in the new library module XcodeProjectPlugin ? Or needs the example code to be adjusted (further then I bug I mentioned below in the comments)? import PackagePlugin @main struct MyPlugin: BuildToolPlugin {? /// This entry point is called when operating on a Swift package. func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] debugPrint(context) // BUG: needs to return an array !!!!!!!!!!!!!!!!!!!!!! } } #if canImport(XcodeProjectPlugin) import XcodeProjectPlugin extension MyPlugin: XcodeBuildToolPlugin { /// This entry point is called when operating on an Xcode project. func createBuildCommands(context: XcodePluginContext, target: XcodeTarget) throws -> [Command] debugPrint(context) return [] } } #endif
Posted Last updated
.
Post not yet marked as solved
2 Replies
155 Views
We have a Mac app that uses several private GitHub hosted Swift Package Manager packages. The app builds file from within Xcode 13.4 whether the builds are Debug (Run) or Release (Archive). However, when built via xcodebuild in Terminal, we get Error: No such module [our package] on an import [our package] statement in a Swift source file. I've tried many variants of the xcodebuild archive command, but nothing seems to fix the issue. We have two other nearly identical projects that work fine with the packages and build scripts. The command looks like: xcodebuild \ -sdk macosx -target "$target" \ -scheme "$scheme" \ -archivePath "$archivePath" \ -destination "generic/platform=macOS" \ archive or xcodebuild \ -scheme "$scheme" \ -archivePath "$archivePath" \ -destination "generic/platform=macOS" \ archive Again, the app builds fine from within Xcode 100% of the time. I'm sure we're using the latest tools: xcodebuild -version returns "Xcode 13.4 Build version 13F17a" I suspect this either has something to do with the Swift packages all referencing a shared package [our package], but I checked the project and Package.swift files and they all use exactly the same name, urls, and capitalization, and the dependencies seem ok, or perhaps it's because we use Schemes to build the apps in three different flavors - dev, qa, and production - all with unique bundleIDs? We're using branch-based .package dependencies if that matters: .package(name: "OurPackage", url: "https://github.com/account/OurPackage", Package.Dependency.Requirement.branch("main")), I'd appreciate any suggestions on how to debug/resolve this. I've tried creating a smaller reproducible demo project but of course they all work fine. Edit: Per a suggestion on iOS-developers, I ran xcodebuild -resolvePackageDependencies and all of the packages downloaded just fine. No errors.
Posted
by EricS.
Last updated
.
Post not yet marked as solved
0 Replies
47 Views
My iOS app consists of one app target and several local SPM packages. Previously, I had a test plan which only included the app target’s tests, while the packages’ tests were launched separately using the packages’ scheme names. Now, I’m trying to switch to test plans entirely. I included the test targets defined in the packages in the test plan. However, doing so resulted in the following error message, attributed to @testable import statements: Testing failed: Module '<***>' was not compiled for testing Command CompileSwiftSources failed with a nonzero exit code Testing cancelled because the build failed. If I understand it correctly, the error occurs because the Enable Testability (ENABLE_TESTABILITY) build setting defaults to NO, preventing the packages’ internal symbols from being exposed with @testable imports. Since Swift packages do not use Xcode project files, I’m confused about where I should define this setting. Besides that, testability is expected to be enabled only for test and not release builds, while Swift packages don’t support build configurations. Am I missing something? Is there a way to make Swift packages and test plans play nice together?
Posted
by XMaster.
Last updated
.
Post not yet marked as solved
0 Replies
53 Views
Hi, I am developing an app which has a calendar integrated. This calendar comes from a package called CalendarKit (https://github.com/richardtop/CalendarKit ). With this calendar you can access to all the events of you mobile integrated calendar and create new ones, modify them, delete, etc. All the events on you mobile calendar are going to be represented here and the same in the other way, everything that you create here will be represented on you mobile calendar. So the main question is. How can i access to the 'Delete Event' action inside the 'Event Details' view? I know that i can delete an event programmatically, but i need to "modify" the behavior when clicking on the item 'Delete Event'. Is there any possible way to access to this item inside event details and when clicking on it do a custom action?. For example, when clicking i want to: print a text in the console, show an alert, get the EventID of the event deleted, etc. Can somebody help me with this?? Thanks a lot in advance.
Posted
by moraKevin.
Last updated
.
Post not yet marked as solved
0 Replies
59 Views
Given is an app project with two SPM dependencies: one to a source code repro and one to a repro containing in XCFramework. Using "Build Documentation" in Xcode generates the documentation for the app and source framework but not for the XCFramework. Wonder, why the documentation is not generated from the symbol graph of the binary Tried to create a .doccarchive with the framework using "Build Documentation during 'Build'" build setting, but: .doccarchive is not copied when creating a XCFramework after adding .doccarchive to XCFramework, it will not be resolved and downloaded via SPM Is there any way to distribute the documentation of my binary framework over SPM to be displayed in the Documentsbrowser using the "Build Documentation" command?
Posted
by Neuwalker.
Last updated
.
Post not yet marked as solved
1 Replies
100 Views
I have a SPM framework project that includes both Swift code and JSON file resources. With a package file that looks like this: let package = Package( name: "MyTestData", products: [ .library( name: "MyTestData", targets: [ "MyTestData", ] ), ], targets: [ .target( name: "MyTestData", dependencies: [], path: "Sources", sources: ["ios"], resources: [ .copy("payloads"), .copy("snippets"), ] ), ] ) Now all the SPM packages resolve correctly and the code compiles and works, yet the Xcode workspace is showing errors like this: Now payloads and snippets are not projects and I've tried all sorts of variations of path, sources, exclude, resource in my Package file and either I get the errors and everything works, or the errors disappear and the project doesn't work. I don't know what the issue is and there's nothing in the resolving or build logs. Does anyone know what might be the problem here?
Posted
by drekka.
Last updated
.
Post not yet marked as solved
0 Replies
44 Views
Swift Package Manager synthesises a module accessor for bundle resources (as described in WWDC 2020 Session 10169 Swift packages: Resources and localisation and SE-0271 > Runtime Access to Resources Bundle. This is great, but I'd like to supply a different implementation of module. When I try to extend Bundle with my own module accessor the compiler complains that there are two module implementations. Is it possible to disable the SPM resource_bundle_accessor synthesis behaviour?
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.6k Views
We are explicitly using Package.resolved to be sure every developer is using the same version. This works like a charm with Xcode 12 in fast lane but we can't make this work anymore in Xcode 13 although it works wonderfully when Xcode itself (not xcodebuild) — a.k.a. the IDE — resolves. Why? Command line invocation: 310[16:06:53]: ▸ /Applications/Xcode-13.0.0.app/Contents/Developer/usr/bin/xcodebuild -resolvePackageDependencies -workspace MyApp.xcworkspace -scheme MyApp -disableAutomaticPackageResolution 311[16:06:53]: ▸ User defaults from command line: 312[16:06:53]: ▸ IDEDisableAutomaticPackageResolution = YES 313[16:06:53]: ▸ IDEPackageSupportUseBuiltinSCM = YES 314[16:06:54]: ▸ Resolve Package Graph 315[16:06:56]: ▸ Checking out 5.12.0 of package ‘GRDB.swift’ 316[16:06:57]: ▸ Resolved source packages: 317[16:06:57]: ▸ MyApp: (null) 318[16:06:57]: ▸ xcodebuild: error: Could not resolve package dependencies: 319[16:06:57]: ▸ Couldn’t check out revision ‘32b2923e890df320906e64cbd0faca22a8bfda14’: 320[16:06:57]: ▸ fatal: reference is not a tree: 32b2923e890df320906e64cbd0faca22a8bfda14 321[16:06:57]: ▸ cannot update Package.resolved file because automatic resolution is disabled 322[16:06:57]: ▸ fatalError This happens not only with GRDB but with others as well. To clarify: The revision exists at https://github.com/groue/GRDB.swift/commit/32b2923e890df320906e64cbd0faca22a8bfda14
Posted
by stuffmc.
Last updated
.
Post not yet marked as solved
0 Replies
40 Views
How to get info about the exact version that is used in a build that is going for AppStore publications? Is it one specified in "iOS Deployment Target" in Build Settings? My iOS app is published on AppStore. And users with different iOS versions can install it (15.0, 15.1, ..., 15.5, ...). To my understanding, Apple frameworks and packages like SwiftUI, Foundation, Combine, etc. can have differences for different iOS versions.
Posted
by msharhan.
Last updated
.
Post not yet marked as solved
3 Replies
130 Views
Hi all, I have been facing a problem while loading a file from the firebase storage. Basically in my code i have a data model which is the file/document (pdf in this case), a manager which goes into the database of Firebase to fetch the object and finally two views, one to list the files fetched and another one to show the document. I can fetch all the documents with their specific data, pass them to my view and then show the document pdf in another view. Everything seems correct but the problem comes when opening one of this docs. First, the doc doesn't open at first so you need to close the view and try to open the doc again. Then when i want to open another doc from my list, when i click on it the previous document is shown and not the correct one, so i need to do the same, close the view and click again on the doc to open the correct one. So at the end what i'm looking for is to open the doc just clicking once but i don't know where is my problem. List of docs: 1st time: 2nd time: 2nd doc but 1st time: 2nd doc and 2nd time clicking on it: Here is my code Model: struct DocumentoPdf {     let titulo: String     let docUrl: URL?     let id: String     let storageUrl: String } Manager which fetches the documents from firebase: final class DatabaseManager { [...]     public func getNovedades(completion: @escaping ([DocumentoPdf]) -> Void) {         database.collection("novedades").getDocuments { snapshot, error in             guard let documents = snapshot?.documents.compactMap ({ $0.data() }), error == nil else {                 return             }             let novedades: [DocumentoPdf] = documents.compactMap({ dictionary in                 guard let id = dictionary["id"] as? String,                       let titulo = dictionary["titulo"] as? String,                       let docUrlString = dictionary["docUrl"] as? String,                       let storageUrl = dictionary["storageUrl"] as? String else {                           return nil                       }                 let novedad = DocumentoPdf(titulo: titulo,                                            docUrl: URL(string: docUrlString),                                            id: id,                                            storageUrl: storageUrl)                 return novedad             })             completion(novedades)         }     } } First View: class NovedadesViewControllerViewModel {     let docUrl: URL?     var docData: Data?     init(docUrl: URL?) {         self.docUrl = docUrl     } } class NovedadesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, PDFViewDelegate {     private var tableView =  UITableView()    private var doc = PDFDocument()     public func configureDocPdf(with viewModel: NovedadesViewControllerViewModel) {         if let data = viewModel.docData {             doc = PDFDocument(data: data)!         }         else if let url = viewModel.docUrl {             // fetch doc & cache             let task = URLSession.shared.dataTask(with: url) { [weak self] data, _, _ in                 guard let data = data else {                     return                 }                 viewModel.docData = data                 DispatchQueue.main.async {                     self?.doc = PDFDocument(data: data)!                 }             }             task.resume()         }     }     private var novedades: [DocumentoPdf] = []     private func obtenerNovedades() {         DatabaseManager.shared.getNovedades() { [weak self] novedades in             self?.novedades = novedades             DispatchQueue.main.async {                 self?.tableView.reloadData()             }         }     }     override func viewDidLoad() { [...]         obtenerNovedades() [...]     } [... sections, rows in section...]     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         let novedad = novedades[indexPath.row]         let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)         cell.textLabel?.text = novedad.titulo         return cell     }     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {         let novedad = novedades[indexPath.row]         switch indexPath.section {         case 0:             configureDocPdf(with: .init(docUrl: novedad.docUrl))             let lectorPdfView = LectorPdfViewController(doc: self.doc, nameDoc: novedad.titulo)             self.present(lectorPdfView, animated: true, completion: nil)         default:             break         }     } } Second View to load the pdf: class LectorPdfViewController: UIViewController, PDFViewDelegate {     private let navBar = UINavigationBar()     private let pdf = PDFView()     let nameDoc: String     let doc: PDFDocument     init(doc: PDFDocument, nameDoc: String) {         self.doc = doc         self.nameDoc = nameDoc         super.init(nibName: nil, bundle: nil)     }     required init?(coder: NSCoder) {         fatalError()     }     override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .systemBackground         view.addSubview(navBar)         view.addSubview(pdf)         pdf.document = self.doc         pdf.delegate = self         let item = UINavigationItem(title: self.nameDoc)         navBar.setItems([item], animated: false)         navBar.barTintColor = .systemBackground     }     override func viewDidLayoutSubviews() {         navBar.frame = CGRect(x: 0,                               y: 0,                               width: view.frame.size.width,                               height: 50)         pdf.frame = CGRect(x: 0,                            y: navBar.frame.height,                            width: view.frame.size.width,                            height: view.frame.size.height - navBar.frame.height)     } } Please if someone can help me with this will be fantastic. I hope you understood my code and my problem. Sorry for my bad english Thank you so much in advance
Posted
by moraKevin.
Last updated
.
Post not yet marked as solved
0 Replies
56 Views
Hello, I want to add a .mlmodel to my swift package to have a test to verify that the compilation is working. targets: [     .target(       name: "packageName",       dependencies: ["package1"]     ),     .testTarget(       name: "packageNameTests",       dependencies: ["packageName"],       resources: [         .copy("Resources/testmodel.mlmodel"),       ]     )   ] My problem is the .mlmodel is always as a compiled model after bundling let docsPath = Bundle.module.resourcePath! let docsArray = try fileManager.contentsOfDirectory(atPath: docsPath)     print(docsArray) leads to ["testmodel.mlmodelc"] I am excepting testmodel.mlmodel to be present instead. I find it strange that copy is processing the ressource. Is there a workaround ? I am using Xcode 14 beta but there is a similar post on StackOverflow without answer regarding this issue https://stackoverflow.com/questions/64298356/how-to-add-uncompiled-mlmodel-to-xcode-unittests-bundle that got this problem with Xcode 12 Thank you
Posted
by AymericF.
Last updated
.
Post not yet marked as solved
0 Replies
69 Views
Hi - I'm blocked by a spurious error in XCode I can't shake, in an iOS/Catalyst app project in swift with swift packages. The target has an iOS deployment version of 14.1, but XCode UI behaves like the target is set to 13.0: The package product 'LIB' requires minimum platform version 14.0 for the iOS platform, but this target supports 13.0 The command line builds fine: xcodebuild -configuration Release -scheme 'Study (iOS)' # (also Debug config) I'm sure I must be missing some configuration, but I have set the iOS/catalyst deployment version > 14 in project and target. To confirm: I'm using the same target scheme in XCode UI as the command-line build I fail in the UI using any relevant target devices (i.e., over iOS 14, mac catalyst or ipad) The project selector clearly shows target 14.1 (project/Deployment target/iOS deployment target) The project/target UI clearly shows deployment target 14.1 (project view, 'Study (iOS)' target, iOS Deployment Target) Same result when using version 15.0 instead of 14.1 Same result when disabling catalyst support and targeting iPad Same result with or without a derived mac catalyst product bundle identifier Same result for macOS targets 11..12.4 14.0 = macOS 11.0 15.0 = 12.0 Same result after creating a new run scheme. Scanning all files in the project confirms these settings and does not show a relevant 13 e.g., in "IPHONEOS_DEPLOYMENT_TARGET[sdk=macosx*]" and IPHONEOS_DEPLOYMENT_TARGET I'm running macOS 12.4, XCode 13.4 (13F17a), default 5.6 toolchain, with packages declaring 5.6 toolchain No external xcconfig files In the XCode UI, I've done clean builds and reset the package cache I've deleted XCode's Derived Data and restarted mac I'm also developing packages (and have cleaned .build and .swiftpm directories) but app package dependencies are pulling from remote repository (i.e., not using local packages) So: Any clue as to why XCode believes the target is 13 and not 14.1? How I can debug this? Is there some way XCode can indicate the target triplet and SDK and how it is derived? Is the next step to recreate the project? Thanks!
Posted
by pde5i.
Last updated
.
Post not yet marked as solved
16 Replies
4.7k Views
I keep getting a Xcode Previews error in Xcode 12 from a package that imports other packages. As soon as I remove the dependency I'm able to see the SwiftUI preview. I'm only able to use previews in packages that have no dependencies The error I get is: "LoadingError: failed to load library at path...Library not loaded " then it point to the dependency that it could not load in the current package. How can I access Xcode Previews from a package that depends on other packages?
Posted
by iamlogiq.
Last updated
.
Post not yet marked as solved
0 Replies
75 Views
Hi, I am a developer working in a bank swift library that uses Chilkat iOS am. Currently, the library can be installed by Cocoapods. The podspec have these lines to let their installation: s.source_files = ['Project/Classes/**/*', 'Project/Libs/ios-chilkat/include/**/*.h'] s.vendored_frameworks = ['Project/Libs/ios-chilkat/libchilkat.xcframework'] s.pod_target_xcconfig = { 'OTHER_LDFLAGS' => ['-lresolv', '-lpthread', '-lstdc++'] } s.dependency 'Alamofire', '~> 4.9.1' s.dependency 'Dynatrace', '~> 8.215' Now I have to make the library compatible with Swift Package Manager, by I can't achive it. When my library is imported, the "Cko**" classes are not recognized. the package.swift have these lines: .target(             ...             dependencies: [                 "Alamofire",                 "libchilkat",                 .product(name: "Dynatrace", package: "swift-mobile-sdk", condition: .when(platforms: [.iOS]))             ],             path: "Project",             sources: [                 "Classes/.",                 "Libs/chilkat-ios/include/."             ]         ) ... I've been trying for a week now, what can I do?
Posted Last updated
.
Post not yet marked as solved
0 Replies
87 Views
There is a package that I want to use in my iOS app project. Although it lacked certain functionality, the GitHub community is great and it was added by some kind soul. However, as it was not yet merged with original repository, this functionality lives only in the fork. And that's when there came the trouble. Although I'm supplying the Package Manager with the link to the fork, it does a great job in correcting me and points me to the original repo. I've seen that one can lock onto a specific commit hash in this article: https://www.swiftbysundell.com/articles/managing-dependencies-using-the-swift-package-manager/#adding-remote-dependencies, but it was only shown for Packages, not Projects in Xcode. Is there a way out of it? Is there a file I could edit to bring me the functionality I crave before I grow old?
Posted Last updated
.
Post not yet marked as solved
0 Replies
77 Views
Hi guys, i'm encountering an issue that makes me crazy. Dunno if there's a solution available :D I have a main apps that imports a lot of local SPM modules; some of them are considered base common models, imported by other modules (e.g. Module1 is a base module with common resources for Module2 and Module3). Unfortunately when i import all the modules, all the resources inside the Module1 seems not loaded (not found!) correctly. Module1 (common model) targets: [ .target(name: Module1, dependencies: [], resources: [ .process("Resources") ]), Module2 targets: [ .target(name: Module2, dependencies: [ .byName(name: Module1), ], resources: [ .process("Resources") ]), Module3 targets: [ .target(name: Module3, dependencies: [ .byName(name: Module1), ], resources: [ .process("Resources") ]), Example of errors i'm encountering: Calls from main app (.workspace) with imported SPM Module1, 2, 3. Bundle.module.path(forResource: <xib file in Module1>, ofType: "nib") => nil Bundle.module.loadNibNamed(<xib file in Module1>, owner: self, options: nil)?.first as? UIView => nil Do you have any idea how to load correctly all the dependencies?
Posted Last updated
.
Post not yet marked as solved
3 Replies
345 Views
As of Xcode 13.3, binary SPM dependencies are no longer included in our app's Frameworks folder. When our app is launched on a device, it crashes with a Library not loaded: @rpath/... error with the list of attempted framework search paths. Is this a known issue with Xcode 13.3 and 13.3.1? Is there a workaround?
Posted Last updated
.
Post marked as solved
7 Replies
20k Views
I have a project I've been working off of for a few years now that makes use of local Swift Packages. In my workspace, I have a "Kit" project that generates a framework using several local Swift Packages as dependencies. In Xcode 12, the local Swift packages resolve correctly and compiles, but each beta of Xcode 13 gives me the error: "[ProjectName].xcodeproj Missing package product '[LocalSwiftPackage]'" Clearing the package cache, derived data, or restarting the application does not resolve the issue. Only Swift Packages that are remotely loaded from a URL are compiled correctly. Using local packages to separate module code, while still being able to edit in the same project, has been essential to my workflow and would hate to see Xcode 13 release with these breaking changes, and I have not seen this issue listed in the known issues for the Xcode 13 release notes. Has anyone else experienced this issue or found a workaround?
Posted Last updated
.