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
1 Replies
107 Views
I want to generate a DocC documentation for an internal Swift Package with the help of SwiftDocC plugin using the following command: The internal framework uses realm-core and realm-cocoa. $ swift package --disable-sandbox preview-documentation --product InternalFramework Actual Results If I build the DocC files via Xcode the build documentation is generated. But if I use the above command on the terminal to generate. There is an error shown on the terminal and the framework fails to build the documentation. The following is the error shown on the terminal Computing version for https://github.com/realm/realm-cocoa.git Computed https://github.com/realm/realm-cocoa.git at 10.28.1 (0.64s) Computing version for https://github.com/realm/realm-core Computed https://github.com/realm/realm-core at 12.1.0 (0.36s) error: Couldn’t update repository submodules: fatal: could not get a repository handle for submodule 'tools/vcpkg/ports' I do not understand whether it is a DocC based issue or a realm issue. Steps & Code to Reproduce Running the following command causes the error: $ swift package --disable-sandbox preview-documentation --product InternalFramework I am not able to understand the root cause of the error.
Posted
by rrlji.
Last updated
.
Post not yet marked as solved
0 Replies
97 Views
I work with a number of enterprise clients and one thing we often do is have various frameworks that are optional depending on what type of build we are doing. A common example being to include a framework that contains an embedded server for testing, demo or debugging purposes. Prior to SPM we would link those frameworks as "Optional" and run a script phase after the build that removed them from the Frameworks directory of the app if it was a "Release" build. Now I have an Xcode project that includes a number of SPM package, one of which is an embedded server which in turns references several other packages I'd like to exclude form a "Release" build. But I cannot figure out how to do this. Can I make the inclusion of a package optional? Or somehow remove it after linking? In Swift I can write #if canImport(MockServer) but I cannot see how to actually make MockServer an optional include. Any ideas?
Posted
by drekka.
Last updated
.
Post not yet marked as solved
0 Replies
181 Views
The Situation Our SwiftUI project uses three Swift packages (hosted on GitHub in private repositories): a custom UIKit package a custom BackendKit package a custom ApplicationKit package From the filesystem perspective it looks like this: OurApplication/ CustomUIKitPackage/ CustomBackendKitPackage/ CustomApplicationKitPackage/ I added all three packages as local dependencies (because we need to edit them constantly) by dragging their folders into the project workspace. In the Xcode project navigator they are now under a Packages group. I also added remote dependencies for all three packages to the Xcode project by using their git@github.com:... URL. Access to these three private repos are already granted. The Problem With this configuration I can work on the project and on all three packages as well. I can make changes, run tests, all the stuff - No problem. Triggering an Xcode Cloud build it will always fail saying something weird of: an out-of-date resolved file was detected at /Volumes/workspace/repository/MY_PROJECT.xcworkspace/xcshareddata/swiftpm/Package.resolved, which is not allowed when automatic dependency resolution is disabled; please make sure to update the file to reflect the changes in dependencies. Running resolver because the following dependencies were added: 'CustomBackendKitPackage' (git@github.com:MY_COMPANY/CustomBackendKitPackage.git)xcodebuild: error: Could not resolve package dependencies: Removing all three local dependencies out of MY_PROJECT/Packages/*, pushing everthing to GitHub and running an Xcode Cloud build again, it works as expected. All three remote dependencies with its git@github.com:... URLs are being used correctly and the Xcode Cloud build turns green. The Question How do I configure Xcode correctly so that I have my local packages for development at the same time as Xcode Cloud uses the remote references?
Posted
by woodbytes.
Last updated
.
Post not yet marked as solved
1 Replies
139 Views
I'm trying to use Previews in a Swift Package in Xcode 14b2 but it's not working (it was working in Xcode 13). I have the following error message but I don't know how to solve it. "XCPreviewAgent.app" must be code signed in order to use on-device previews. Check your code signing settings for the target. com.apple.dt.UVPreviewAgent-watchOS.watchkitapp {     url: file:///Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchOS.platform/Developer/Library/Xcode/Agents/XCPreviewAgent.app     version: 20.0.32.2     attributes: [         ObjectIdentifier(0x00000001638e5d18): ["OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1"],     ] }
Posted
by alpennec.
Last updated
.
Post not yet marked as solved
4 Replies
183 Views
We tried to build with Xcode 14 and quickly ran into SPM issues, we have one binary submodule for a framework. Has something changed in how package location are described? Can't seem to find it as a legit framework. Can "cd" and inspect, everything appears to be in place. Showing Recent Errors Only local binary target 'Service.iOS' does not contain expected binary artifact named 'Service.iOS' Works without issues in Xcode 13.4.1 and can switch between the versions. Any ideas?
Posted Last updated
.
Post not yet marked as solved
4 Replies
734 Views
When I try to build my iOS app using Xcode Cloud, it encounters an error when trying to resolve packages: an out-of-date resolved file was detected at [path to package.resolved], which is not allowed when automatic dependency resolution is disabled; please make sure to update the file to reflect the changes in dependencies Looking at my package.resolved file, it all seems to be in order. What can I do to fix it?
Posted Last updated
.
Post not yet marked as solved
1 Replies
160 Views
Is there a logical disjunction operator or function in Swift? Even better, is there a logical disjunction that works with optional variables instead of boolean variables that returns an object when true, and returns nil when false? A logical disjunction evaluates two boolean variables, and if at least one of them is true, then the return value is true. If neither variables is true, then the return value is false.
Posted Last updated
.
Post not yet marked as solved
0 Replies
97 Views
Hello, i am currently trying to implement a pre build script execution in a package. I am using this tutorial to implement it. But it only shows how to use the pre build feature with an already existing feature. I want to execute a skript on my pc every time i build the project. I can't use apples prebuild skript feature in the build settings because it is a package. Right now my code looks like this: import Foundation import OSLog import PackagePlugin @main struct GenerateLocalizer: BuildToolPlugin {     do {       let commandlineOutput = try shell("./testScript.sh")     } catch {     }     return [.prebuildCommand(displayName: "Generate Strings", executable: PackagePlugin.Path("./scrips/generate_strings.sh"), arguments: [], outputFilesDirectory: target.directory)]   }   func shell(_ command: String) throws -> String {     let task = Process()     let pipe = Pipe()     task.standardOutput = pipe     task.standardError = pipe     task.arguments = [command]     os_log("%{public}@", log: log, task.arguments?.joined(separator: " ") ?? "not found")     task.launchPath = "/bin/zsh"     task.standardInput = nil     try task.run()     let data = pipe.fileHandleForReading.readDataToEndOfFile()     let output = String(data: data, encoding: .utf8)!     return output   } } and my Package file looks something like that       name: "CustomSdk",       dependencies: ["CustomSdk-Objc"],       path: "CustomSdk",       exclude: ["Info.plist", "CustomSdk.podspec"],       plugins: [         .plugin(name: "GenerateLocalizer")       ]     ),     .plugin(name: "GenerateLocalizer",         capability: .buildTool(),         dependencies: ["CustomSdk-Objc"]     ) It gets called properly but when want to write files in my "testScript.sh" it only says: Operation not permitted. Anyone got any ideas how to fix this or is there another way to utitlize custom scripts with custom packages? Greetings Ben
Posted
by benkai.
Last updated
.
Post not yet marked as solved
0 Replies
96 Views
We've been looking for a while for a solution to updating package dependencies from the command line. Does Xcode 14 provide a way to do it? I've been searching and haven't seen anything. Anyone saw something? We've had xcodebuild -resolvePackageDependencies for a while, but as many people point out here and in Stack Overflow, this option does not actually update the dependencies like the Update to Latest Package Versions menu command does in Xcode. The goal is to have an automated way to keep dependencies up-to-date, so we can run a script nightly that produces a PR which someone on the team can verify before merging.
Posted Last updated
.
Post marked as solved
1 Replies
125 Views
Hi, I try to instatiat a ViewController vom a local SPM Package but I always get the error Could not find a storyboard. let myViewController = UIStoryboard(name: ",yStoryboard", bundle: Bundle(url: Bundle.main.url(forResource: "myModule_myModule", withExtension: "bundle")!)).instantiateViewController(withIdentifier: "MyViewController") This code works when using it as an remote package. What I'm doing wrong? Thanks Bernhard
Posted Last updated
.
Post marked as solved
6 Replies
1.1k Views
Hello! I am struggling with the most basic things :-( I created a Swift Package with the wizard and left it basically untouched, only added a func: public struct TestPackage {     public init() {     }     public static func hello()     {         print("Hello, World!")     } } It just build fine. Now I created a second project, this time a SpriteKit iOS app. In the file list on the left, right-clicked on "Packages" -> "Add Packages ..." -> "Add Local" and selected the root directory of TestPackage (containing the Package.swift) The Package now correctly appears in the "Packages" folder. Opening a random Swift file in said SpriteKit iOS app, I expect to be able to import TestPackage But it tells me "No such module TestPackage". Searching the internet, I somewhere read that I have to add the package also to the "Frameworks, Libraries and Embedded Content" section in the project's target settings, but I can't. Hitting the "+" button there does not give me my library in the list of suggested libraries. Via "Add Other" -> "Add package dependency" -> "Add Local ..." I can again select the root directory of my library, but other than showing up twice in the left-side folder view (and not in said Frameworks, Libraries and Embedded content", I have no luck in importing it to my code. What am I doing wrong?
Posted
by s_zapo.
Last updated
.
Post marked as solved
6 Replies
2.2k Views
Hello everyone, I have a problem with my Xcode, when I try to add package dependency it stuck on verifying screen, at the beginning of the preparing to validate part. anyone has the same problem?
Posted
by onqun.
Last updated
.
Post not yet marked as solved
1 Replies
165 Views
Hi! I am wondering if there is a way to enable resources from a Swift Package to be stored with the ODR system? I have tried moving my asset catalogs to a Swift Package and while my tags for each asset were intact, the assets disappeared from the "Resource Tags" tab in the Project Settings. Is there any other way to make them work? I would love to be able to move these asset catalogs to a package to make the project more modular and this is a blocker for me at the moment.
Posted Last updated
.
Post marked as Apple Recommended
3.7k Views
Hello! We have some resources included as part of our test target like so:         .testTarget(             name: "MyProjectTests",             dependencies: ["MyProject"],             resources: 							[.process("Assets/Test_5s.mov")]) However, when running the following command: swift package generate-xcodeproj the generated package does not include the assets. Additionally the code to access the resources won't compile because there is no auto-generated file to provide the 'module' extension for 'Bundle'. Bundle.module.url(forResource: "Test_5s", withExtension: "mov") results in a "Type 'Bundle' has no member 'module'" compilation error. Is this a known issue, or am I approaching this incorrectly if I want to have a project for the package? Currently using Xcode 12 beta 2
Posted
by jeff97.
Last updated
.
Post not yet marked as solved
0 Replies
147 Views
Hi, We are currently using xcframework dependencies in our large project and we've got a compile time of ~15min on CircleCI. We are trying to move a few dependencies from xcframework to Swift Package Manager but I'm seeing that there is a lot of time being added to our compile time as xcodebuild will always compile spm also. I've tried caching SourcePackage to limit the download steps but I wasn't able to find a way to cache the spm dependency builds also. Is this possible ? What is the strategy of compiling large projects with multiple SPM dependencies on a CI system.
Posted
by mmdumiwip.
Last updated
.
Post not yet marked as solved
0 Replies
122 Views
Hello everyone. The project I am working on is shifting from using CocoaPods to SPM and there is one "wrinkle" I'd like some advice on. The project has several framework projects containing code as well as the main app project. All of these make use of code generators (RSwift, Sourcery) at some point and these need to be run before the main build starts. The problem is that SPM builds do not support the concept of adding script phases so there appears to be no easy way to incorporate these shell tools into the builds. Particularly in the framework projects which are pure SPM packages and therefore do not have your typical project files and build phases. My question is - how to deal with shell based build phases in an SPM world? Currently we are adding these phases in the main app's build. However they are not run before the builds of the SPM dependencies so effectively we have to run the build twice to ensure the code is up to date.
Posted
by drekka.
Last updated
.
Post not yet marked as solved
0 Replies
134 Views
I'm trying to log when a user gets a silent notification using didReceiveRemoteNotification. Here is my code right now: func application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void ) { print("Log here") application.applicationIconBadgeNumber = 0 completionHandler(.noData) } Here is the payload.apns file: "aps" : { "content-available" : 1, }, "acme1" : "bar", "acme2" : 42 If i open Console.app application I can see that the (simulator in this case) wakes up in the background when I drag and drop the payload but it never runs the didReceiveRemoteNotification function. The app is written in SwiftUI and has a seperate AppDelegate file. The app is also using Firebase Analytics and I have tried to set the FirebaseAppDelegateProxyEnabled to "NO" (false). Am I doing something wrong? Note: The function gets called when the app is in the foreground and I drag and drop a normal alert notification (not silent).
Posted
by Rootin.
Last updated
.
Post not yet marked as solved
0 Replies
148 Views
The session on creating a plugin mentioned that you don’t have access to networking. Is this functionality that may come in a future update, or is there no plan to ever add it? My specific use case is to use a public API my company has available, which provides us a JSON payload so we can generate theme resources. I’d love to be able to put our theming code into a Swift Package, but it sounds like I won’t be able to use a plugin to be able to do the code generation that I need to do.
Posted
by Danberry.
Last updated
.
Post not yet marked as solved
1 Replies
1k Views
Just upgraded to Xcode 13. Opened a Swift package i've been working on and getting all kinds of build errors. I clicked "Reset Package Caches" because theres no place to select a run destination, which means I can't clean the project. It crashes when downloading dependencies with this error on one of them saying it can't figure out what "exactItem" is. This has been working fine on multiple versions of Xcode 12. Looks like an Xcode bug, any insight would be appreciated invalidManifestFormat("/var/folders/z5/lvlxhdt138l_7sb148yl_tqc0000gn/T/TemporaryFile.xBESmT.swift:17:76: error: reference to member \'_exactItem\' cannot be resolved without a contextual type\n    .package(url: \"https://github.com/krzyzanowskim/CryptoSwift.git\", ._exactItem(\"1.3.2\"))\n                                      ^", diagnosticFile: Optional(<AbsolutePath:"/Users/simonmcloughlin/Library/Developer/Xcode/DerivedData/iOS-Example-cfdygpazfzfyotasyfwmjjycvhbq/SourcePackages/ManifestLoading/torus-direct-swift-sdk.dia">)) in https://github.com/simonmcl/torus-direct-swift-sdk
Posted
by simonmcl.
Last updated
.