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 Answers
35 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
3 Answers
497 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
0 Answers
29 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 Answers
30 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 not yet marked as solved
2 Answers
409 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
1 Answers
52 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 Answers
625 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 Answers
1.9k 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 Answers
102 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.4k 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 Answers
71 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 Answers
69 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 Answers
77 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 marked as solved
1 Answers
144 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
0 Answers
79 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 Answers
910 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
.
Post not yet marked as solved
0 Answers
114 Views
xcode 13.4 trying move from fat to xcframework. I create the package by: 'swift package init --type library`; Move our sources to Source folder; Generate archive for iOS: xcodebuild archive -scheme TestFramework \ -destination "generic/platform=iOS" \ -archivePath ./Archive-iOS \ -derivedDataPath ".build" \ SKIP_INSTALL=NO \ BUILD_LIBRARY_FOR_DISTRIBUTION=YES . Generate archive for iOS Simulator: xcodebuild archive -scheme TestFramework \ -destination "generic/platform=iOS Simulator" \ -archivePath ./Archive-iOSSimulator \ -derivedDataPath ".build" \ SKIP_INSTALL=NO \ BUILD_LIBRARY_FOR_DISTRIBUTION=YES Generate the xcframework by docs: xcodebuild -create-xcframework \ -framework './Archive-iOS.xcarchive/Products/Library/Frameworks/TestFramework.framework' \ -framework './Archive-iOSSimulator.xcarchive/Products/Library/Frameworks/TestFramework.framework' \ -output './Archive-iOS.xcarchive.xcframework' got error: error: unable to read the file -> ./Archive-iOS.xcarchive/Products/Library/Frameworks/TestFramework.framework/TestFramework Ofc, because on steps 3,4 I haven't this framework in archive. Where can I found correct documentation with step by step for make xcframeworks?
Posted Last updated
.
Post not yet marked as solved
2 Answers
201 Views
I'm trying to compile an Xcode project. I'm getting 2 runtime errors: No such module 'Amplify & /Users/????????/Library/Developer/Xcode/DerivedData/screener_app-gkvpndyzdgqrsreqyokgisatdzav/Build/Intermediates.noindex/screener_app.build/Debug-iphonesimulator/screener_app.build/Objects-normal/x86_64/AuthButtonView.dia:1:1: warning: Could not read serialized diagnostics file: error("Invalid diagnostics signature") (in target 'screener_app' from project 'screener_app') Command CompileSwift failed with a nonzero exit code The screenshot is seen below. I have tried a handful of things: cleaned build folder install/update pods removedderived data I'm not sure what to do from here. Any advice is appreciated.
Posted
by tenicho.
Last updated
.
Post not yet marked as solved
1 Answers
1.1k Views
I have a Swift package that i've been working on for a while. I upgraded to Xcode 13 a month or two ago. I have a couple of large JS files in my package (third party NPM libraries that I can't re-write). Randomly, Xcode will throw an error (but not a real error because I can continue as normal) that It can't load the folder containing the JS files This doesn't prevent me from doing anything, but its irritating to have this error constantly showing up. Is there anything I can do to solve this or is this an Xcode bug?
Posted
by simonmcl.
Last updated
.