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

260 Posts
Sort by:
Post not yet marked as solved
4 Replies
296 Views
Since 2023 Apple have strongly suggested signing XCFrameworks to verify their origins. This has worked perfectly fine for the last year. Seeing that our certificate was about to expire, we revoked it and created a new one which we will use to sign all future releases. However, because that first certificate has been revoked, all previous releases of our XCFramework now have invalid signatures because the certificate they used no longer exists. While an update to the latest XCFramework would solve the issue, that's not always a possibility for people with lower minimum deployment targets that can only run an older version of our XCFramework. In the wwdc video on the topic it states: When the xcframework author's signing certificate expires, Xcode is able to automatically validate that a new certificate for Apple Developer Program identities is from the same developer. Does this mean that if we had not pre-empted the expiry and instead let the certificate expire, we wouldn't have this backwards compatibility issue? The course of action we've had to take is to manually go through all of our releases for the last year and re-sign them with the latest certificate. This doesn't seem like a tenable solution each year. Looking for guidance on how to manage this situation each year.
Posted
by mapierce.
Last updated
.
Post not yet marked as solved
1 Replies
201 Views
Hi all, Here I want to encode OrderedDictionary to JSON file, I use the JSONEncoder below: let encoder = JSONEncoder() encoder.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes] and I declare variables qwe, asd and zxc: var qwe = OrderedDictionary<String, Int>() qwe["bbb"] = 12 qwe["ccc"] = 13 qwe["ddd"] = 14 qwe["bbc"] = 15 var asd = Dictionary<String, Int>() asd["bbb"] = 1 asd["ccc"] = 3 asd["ddd"] = 4 asd["bbc"] = 5 var zxc: KeyValuePairs<String, String> { return [ "zz": "zz", "aa": "aa", "bb": "bb", "cc": "cc", "bc": "bc", ] } After I do try encoder.encode(qwe).write(to: path ,options: .atomic) encoder.encode(asd).write(to: path ,options: .atomic) encoder.encode(zxc).write(to: path ,options: .atomic) the output JSON file format of OrderedDictionary isn't what I expected. The output JSON of OrderDictionary is like this: [ "bbb", 12, "ccc", 13, "ddd", 14, "bbc", 15 ] On the other hand, the output JSON of Dictionary and KeyValuePairs are normal, just with different order: Dictonary: { "ccc" : 3, "bbb" : 1, "bbc" : 5, "ddd" : 4 } KeyValuePairs: { "cc" : "cc", "aa" : "aa", "zz" : "zz", "bb" : "bb", "bc" : "bc" } I also Log these objects after I declare them, the Log show their structure are similar: qwe -> ["bbb": 12, "ccc": 13, "ddd": 14, "bbc": 15] asd -> ["ccc": 3, "bbb": 1, "bbc": 5, "ddd": 4] zxc -> ["zz": "zz", "aa": A"aa", "bb": "bb", "cc": "cc", "bc": "bc"] I thought the OrderedDictionary is similar to Dictionary, but does anyone know why the output of OrderedDictionary is not like this: {"bbb": 12, "ccc": 13, "ddd": 14, "bbc": 15} Or is there any other way I can customize the order of keys in my encoded JSON file? Thank you so much!
Posted Last updated
.
Post not yet marked as solved
0 Replies
134 Views
I'm working on a multi-platform app. I started with a macOS target so I already had functioning buttons using focused values in menus by the time I started working on the iOS target. But in iOS, the buttons that have focus values in them are not working. I narrowed the issue down to the buttons wrapped in the Menu { } view. My workaround has been to swap out focused values for environment values using a platform check #if os(macOS) ... #endif but I was just wondering if this is expected behaviour? I've googled for days and can't find any answers. I setup a simple demo on GitHub . The plus in the toolbar works but the same button in the menu doesn't.
Posted
by yega.
Last updated
.
Post not yet marked as solved
1 Replies
226 Views
I am trying to include custom symbol resources in a swift package for use in other projects. I have read the documentation here: https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package However there is no example code and I have created a very simple project to try and get this working but it does not. .target( name: "TestLibrary", resources: [.process("Resources/Media.xcassets")] ), This is in the Package.swift file and the path relative to the Package.swift file is Sources/TestLibrary/Resources/Media.xcassets. There's a GitHub project with an example custom SF Symbol SVG (but this may not be available in the future): https://github.com/kudit/TestLibrary Including this as a package in a blank Swift Playgrounds App project and just importing the TestLibrary and including TestImageView() in the ContentView technically works (it shows the system full star image, but none of the ways of rendering the test symbol as recommended works. It does work for a few of the options in the #Preview when viewing the project in Xcode. Anyone have any suggestions or know how to get the resources to be accessible from outside the module? I have tried both the .copy( option as well as the .process( option and neither seem to work.
Posted
by kudit.
Last updated
.
Post not yet marked as solved
2 Replies
863 Views
We have separated much of our UI into different packages to reduce complexity and compile time. When we recently tested using new .xcstrings string catalogs, we hit an unexpected problem. Strings extracted from SwiftUI components like Text or Button are extracted into the Localizable.xcstrings in the same package, but the default behaviour of Text(_ key:tableName:bundle:comment:) is to use Bundle.main. When the default behaviour of the string extraction isn't to extract to the main app target, this introduces a very fragile system where it's easy to add code that looks localised, but ends up failing lookup at runtime. I don't feel comfortable that we will always remember to define the correct module every time we create a Text. Also, other components like Button doesn't have an init that takes a Bundle, so we would also have to remember that Button(_ titleKey:action:) can now only be used in a package if we make sure that the main bundle contains a matching key. Is there a way for us to make sure that strings are always extracted to the same place as they are resolved against by default? Either by having strings in packages extracted to an xcstrings file in the main app or having Text default to resolving against the module bundle by default?
Posted Last updated
.
Post not yet marked as solved
0 Replies
238 Views
In a new document-based UIKit app, specifying in the Info.plist an import type identifier of public.log that conforms to public.content, public.data, public.item accomplishes this. In a new document-based SwiftUI multi-platform app, doing the same crashed at the DocumentGroup initializer with the error _SwiftData_SwiftUI/Documents.swift:91: Fatal error: The document type is public.log which does not conform to com.apple.package. This initializer expects the document type to be a package.
Posted
by Curiosity.
Last updated
.
Post not yet marked as solved
1 Replies
320 Views
We use a local swift package in 6 of our app extensions. The product from the local package that we link to each app extension is a dynamic framework. And while the dynamic framework is copied into the final app bundle once, the resource bundles of each target that comprise the dynamic framework is copied into each app extension. I'd much rather have the bundles be copied into the dynamic framework once to prevent app bloat. Here is a visualization of the issue: . └── MyApp.ipa/ ├── MyApp (executable) ├── MyDynamicFramework_TargetA.bundle ├── MyDynamicFramework_TargetB.bundle ├── MyDynamicFramework_TargetC.bundle ├── Frameworks/ │ └── MyDynamicFramework.framework/ │ ├── TargetA │ ├── TargetB │ └── TargetC └── PlugIns/ ├── Widgets.appex/ │ ├── MyDynamicFramework_TargetA.bundle │ ├── MyDynamicFramework_TargetB.bundle │ └── MyDynamicFramework_TargetC.bundle ├── Intents.appex/ │ ├── MyDynamicFramework_TargetA.bundle │ ├── MyDynamicFramework_TargetB.bundle │ └── MyDynamicFramework_TargetC.bundle ├── IntentsUI.appex/ │ ├── MyDynamicFramework_TargetA.bundle │ ├── MyDynamicFramework_TargetB.bundle │ └── MyDynamicFramework_TargetC.bundle ├── NotificationContent.appex/ │ ├── MyDynamicFramework_TargetA.bundle │ ├── MyDynamicFramework_TargetB.bundle │ └── MyDynamicFramework_TargetC.bundle ├── RichPushContent.appex/ │ ├── MyDynamicFramework_TargetA.bundle │ ├── MyDynamicFramework_TargetB.bundle │ └── MyDynamicFramework_TargetC.bundle └── NotificationService.appex/ ├── MyDynamicFramework_TargetA.bundle ├── MyDynamicFramework_TargetB.bundle └── MyDynamicFramework_TargetC.bundle Notice that the resource bundles of Target A, B, and C are copied multiple times causing an unhealthy app size. I'd either like the resource bundles to be copied into MyDynamicFramework or copied once into the app bundle and let the app extensions reference them. Given the SPM + Xcode linking is a black box for the most part, how would I accomplish this?
Posted Last updated
.
Post not yet marked as solved
0 Replies
198 Views
大家好,我正在尝试制作一个关于如何检测手机屏幕前是否有物体的演示。如果有物体,屏幕将显示红色,如果没有物体,则显示绿色。这可能需要调用距离传感器,但我不知道如何调用它。希望大家能给我一个回应。谢谢。
Posted
by Esoting.
Last updated
.
Post not yet marked as solved
0 Replies
531 Views
I've complied with the reason declaration following the links sent by the autogenerated emails for the surface level Runner declaration, however libswift has the incorrect values for the reason codes for UserDefaults. I've checked their github and there is no way to add issues since it is "read-only". I'm also in the dark for who to contact regarding this. Does anyone have any idea how to resolve this aside from manually changing the privacy files? I don't want to have to do this each time I do pod install. ITMS-91055: Invalid API reason declaration - The PrivacyInfo.xcprivacy for the “Frameworks/libswiftObjectiveC.dylib” file contains “DDA9.1” as the value for a NSPrivacyAccessedAPITypeReasons key instead of a valid reason code for using an API in the NSPrivacyAccessedAPICategoryUserDefaults category.
Posted
by DSdevPH.
Last updated
.
Post marked as solved
1 Replies
190 Views
Hello everyone! I am kind a new here and trying to learn Swift. I am getting this error "Expressions are not allowed at the top level" I´ve tried both with an function and without function! func text(){ let number = 120 print(number.isMultiple(of: 3)) } text() Without function let number = 120 print(number.isMultiple(of: 3)) I really appreaciate if you can help me out! My playground app is crashing every time I open it so I´ve got no other choice but to use Xcode Kind regarding Your noob friend!
Posted
by Farrriiaa.
Last updated
.
Post not yet marked as solved
3 Replies
284 Views
I have encountered an issue related to the usage of string catalogs in a Swift package. I created a repository for reproduction. https://github.com/atacan/DiscussionStringCatalogPackage The Readme.md file has all the details. Here is a short summary: The Package.swift file's target has resources: [.process("Resources")], and this Resources folder contains a string catalog. The catalog is correctly populated by the compiler, and German translations are added. Text view is using bundle: .module argument. However, when the scheme run options are changed to German, the UI still displays English text. Xcode throws a warning indicating that the German translation for the text is not found in the Localizable table of the bundle and it says (not loaded). Although the bundle contains translations in the Localizable.strings file. Screenshots of the issue are available in the original README file. I am looking for any insights or solutions to this problem.
Posted Last updated
.
Post not yet marked as solved
2 Replies
304 Views
I've a workspace with multiple packages, and due to the a bug in Xcode I cannot export the app localizations using the Xcode GUI tool, but I need to resort on using a command from terminal xcodebuild -exportLocalizations -localizationPath . -workspace &lt;path_workspace&gt; -sdk iphoneos -exportLanguage en One of my packages contains some macros, and I use them from my code without any problem, the code compile But when I try to export localizations using that command, the build fails due to "compiler plugin not loaded" So I cannot use Xcode normal exporting because Xcode bug, and cannot export by running a command due to the macro problem What should I do? It is very discouraging this situation, do you have any suggestion? I've found a similar problem
Posted
by Playrom.
Last updated
.
Post not yet marked as solved
0 Replies
526 Views
When distributing a 3rd party SDK as an XCFramework in order to include the privacy manifest to the bundle you need to include the resources key in the target configuration to point to the correct file, for example: resources: [.process("Resources/PrivacyInfo.xcprivacy")] However, when distributing the xcframework as a binaryTarget resources is not available. How can I include my privacy manifest when configuring Package.swift ?
Posted
by moshekr.
Last updated
.
Post not yet marked as solved
2 Replies
345 Views
objc[27000]: Class XROS1_1SimRuntime is implemented in both /Library/Developer/CoreSimulator/Volumes/xrOS_21O209/Library/Developer/CoreSimulator/Profiles/Runtimes/xrOS 1.1.simruntime/Contents/MacOS/xrOS 1.1 (0x1025f80e0) and /Library/Developer/CoreSimulator/Volumes/xrOS_21O5181e/Library/Developer/CoreSimulator/Profiles/Runtimes/xrOS 1.1.simruntime/Contents/MacOS/xrOS 1.1 (0x1027c00e0). One of the two will be used. Which one is undefined. error: Tool terminated by signal 'Segmentation fault: 11' This build failed issue occur every time when I play build
Posted
by B2D.
Last updated
.
Post not yet marked as solved
0 Replies
171 Views
Would like to be able to bring up the iOS keyboard in a SwiftUI view without having to use a TextField? The goal would be to capture each keyup, or keydown, using .onKeyPress While I thought I could create a TextField not visible to the user, was hoping there was a cleaner way.
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
0 Replies
163 Views
Hi, I'm facing an issue with triggering sign in. The button only triggers after a long press, not just simple tap. There's no scrollView, just ZStack. I've already tried deleting all the layers and components except this button, still nothing.
Posted
by akksupper.
Last updated
.
Post not yet marked as solved
1 Replies
348 Views
I am getting the following error after xcode was updated, it is saying that i cant find the googlemobileads framwork, however i have since, restarted my mac, restart xcode, reset simulator, erare all content and settings, delete derivadata, delete the devices and create new one. also check that the framework is being link. see below Apple i need help here
Posted
by yun22.
Last updated
.
Post not yet marked as solved
0 Replies
208 Views
[!] The Runner [Debug] target overrides the ENABLE_BITCODE build setting defined in `Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig'. This can lead to problems with the CocoaPods installation How to fix this error ?
Posted Last updated
.