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

264 Posts
Sort by:
Post not yet marked as solved
0 Replies
61 Views
Hello, we recently added a build plugin to our swift package and we have a Xcode project that uses the swift package as a dependency and we build that Xcode project from the command line using xcodebuild build-for-testing. After we added that build plugin to the swift package, xcodebuild now fails and says this: If I remove that build plugin from the swift package then xcodebuild build-for-testing will build successfullly. It is also worth noting then when we run the xcodebuild build-for-testing command we pass in multiple -destination flags. If we pass one -destination flag then xcodebuild succeeds even with the build plugin. So it seems like the issue is around having multiple destination flags and a build plugin added. This sounds like a bug within xcodebuild. Any thoughts or ideas on why this isn't working would be helpful! Here is an example of what our full xcodebuild command looks like: xcodebuild build-for-testing -project “SomeProject” -scheme “SomeScheme” -configuration Debug -destination ‘SomeDestination1’ -destination ‘SomeDestination2’ -destination ‘SomeDestination3’ -disableAutomaticPackageResolution -onlyUsePackageVersionsFromResolvedFile -skipPackageUpdates -skipPackagePluginValidation -allowProvisioningUpdates DEVELOPMENT_TEAM=SomeTeam Thank you!
Posted
by klinee101.
Last updated
.
Post not yet marked as solved
0 Replies
44 Views
I got log that "You have changed the icon for ~", but icon was not changed. There is no error and warning. I set assets, Alternate App Icon Sets, info and checked "include all app icon assets". here is info <key>CFBundleIcons</key> <dict> <key>CFBundlePrimaryIcon</key> <dict> <key>CFBundleIconFiles</key> <array> <string>AppIcon</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> <key>CFBundleAlternateIcons</key> <dict> <key>blackCircle</key> <dict> <key>CFBundleIconFiles</key> <array> <string>blackCircle</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> </dict> </dict> blackCircle is a name of image in assets. I wrote blackCircle in Alternate App Icon Sets. I don't know what to do. I tried all I could find in website
Posted
by Ryotafdsa.
Last updated
.
Post not yet marked as solved
0 Replies
54 Views
Hello, When I build an XCode project with the Apple Silicon chip, I have some issues. The project contains Pods and Swift Packages. I could not run the application at all and always got the following error: Could not find module '***' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator, at: *** I try to resolve this issue. Always embed swift standard libraries = YES Build Active Architure Only = YES UIRequiredDeviceCapabilities = armv7 Excluded Architectures > Debug > Any iOS Simulator SDK arm64 add Open Using Rosetta Excluded Architectures > Debug > Any iOS Simulator SDK arm64 remove However, issue always come to me. :( Do you have any solution for this problem ? Thank you by advance !
Posted
by Gooood.
Last updated
.
Post not yet marked as solved
0 Replies
88 Views
Within Xcode when initializing the client via code below, do I insert this code in my app declaration Swift file or can it be just another Swift file included in my app? Thanks! let client = Graph.Client( shopDomain: "your-shop-name.myshopify.com", apiKey: "your-storefront-access-token", locale: Locale(identifier: "en_US") )
Posted Last updated
.
Post not yet marked as solved
6 Replies
329 Views
So I am running into a very strange issue. Xcode is deleting the Package.resolved file after every build, resulting in having to manually Reset Package caches after every build/run/test. Extremely annoying, any idea why this is happening?
Posted
by janniet.
Last updated
.
Post not yet marked as solved
0 Replies
109 Views
Hi, I have a view that takes an optional binding boolean variable. I'd like to pass a variable to it from certain views only. The problem I'm having is when I pass a variable, I get the error "Cannot convert value of type 'Binding' to expected argument type 'Binding<Bool?>'", and when I don't, I get the error "Missing argument for parameter 'toggle' in call". Below Is the code I have. Thank you. Heading(text: "Heading1") // error: Missing argument for parameter 'toggle' in call Heading(text: "Heading2", toggle: $newEntry) // Cannot convert value of type 'Binding<Bool>' to expected argument type 'Binding<Bool?>' struct Heading: View { @State var text: String @Binding var toggle: Bool? var body: some View { VStack { Spacer() .frame(height: 25) HStack { Text(text) .font(.system(size: 36)) Spacer() if text == "str" { Button(action: { toggle!.toggle() }) { Image(systemName: "plus") .foregroundColor(.black) .font(.system(size: 36)) } } } Spacer() .frame(height: 25) } } }
Posted Last updated
.
Post not yet marked as solved
0 Replies
105 Views
I am trying to setup a Virtual Machine environment for our CI/CD and I get the following error when I try to clone the source packages of the xcodebuild command in the disk mounted by the host in the vm to use it as a cache: Error Domain=NSPOSIXErrorDomain Code=62 "Too many levels of symbolic links" This error only shows up when the path of the option "clonedSourcePackagesDirPath" is set to the disk mounted by the host. On a directory inside the vm itself it works fine. We get the error with the macos target of the Lottie.xcframework since it's the only one to use symlink. We check and there is no cycle to be found. Anyone has any idea of how to solve this issue ? Or an explanation of what's going on there ?
Posted
by MaelRB.
Last updated
.
Post marked as solved
6 Replies
1.8k Views
I have an iOS app by using a swift package to hold most of the logic. However, the previews of SwiftUI views often fail with following error: HumanReadableSwiftError BuildError: failedToGenerateThunkInfo(Error Domain=com.apple.xcbuild Code=19 "could not generate preview info: noTargetBuildGraph" UserInfo={NSLocalizedDescription=could not generate preview info: noTargetBuildGraph}) To reproduce this, please clone https://github.com/pointfreeco/isowords and check for preview of ChangelogView.
Posted
by surajb.
Last updated
.
Post marked as solved
2 Replies
132 Views
Hey, I'm working on a new multi-platform application, and part of the application requires a calendar. I've created Day, Week, and Month calendar and they are all working as expected on Mac/iPhone and iPad. So I decided that I would make them a Library/Package and share with the community. I created a package project, moved all the working code into it, and then added the package into my project as a local dependency. Now I'm getting lots of errors in the package code about everything is only available in macOS 10.15. It's not the code as I know it works. I have platforms: [ .macOS(.v10_14), .iOS(.v15) ] This is my first attempt at a package. Is there something I'm not doing? Thanks, Mark
Posted
by MPHaskins.
Last updated
.
Post not yet marked as solved
4 Replies
199 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
148 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
84 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
149 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
763 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
176 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
223 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
139 Views
大家好,我正在尝试制作一个关于如何检测手机屏幕前是否有物体的演示。如果有物体,屏幕将显示红色,如果没有物体,则显示绿色。这可能需要调用距离传感器,但我不知道如何调用它。希望大家能给我一个回应。谢谢。
Posted
by Esoting.
Last updated
.
Post not yet marked as solved
13 Replies
2.1k Views
Since Xcode 15.3 it has become impossible to build our project more twice in a row without encountering a batch of "internal inconsistency error: never received target ended message for target ID …". This issues appeared a few months ago (15.0 i think, but i'm not sure), but xcode 15.3 makes it almost unusable. We're a team of 3 iOS devs, and we're all having the problem. Our project involves a lot of SPM packages, a few cocoa pods, a few iOS Frameworks, and a bit of swiftgen. Nothing particularly special for a large project, and no custom build steps that does anything fancy. It is now to the point where we're looking for alternative to xcode, because we can't decently kill xcode and restart every time we have to build our code...
Posted Last updated
.
Post not yet marked as solved
0 Replies
417 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
.