Post

Replies

Boosts

Views

Activity

SwiftUI Previews broken on Swift Package with dependencies
Hello! Previously, using content from one Swift Package in the UI of another would cause preview failures. Now, with Xcode 16, this issue has been improved, and the preview feature is working, though occasional crashes still occur. I have submitted a report regarding this issue. I’ve encountered some issues while developing a SwiftUI-based application, particularly when using Xcode’s SwiftUI preview feature, which frequently crashes. My app supports both macOS and iOS. Due to the differences between the platforms, I’ve had to implement some pages using UIKit and reference a few UIKit-based open-source frameworks. For instance, I’m using the LazyPager library, which only supports iOS. During runtime, I ensure LazyPager is only compiled for iOS by using .product(name: "LazyPager", package: "LazyPager", condition: .when(platforms: [.iOS])), which works as expected. However, when I use Xcode’s SwiftUI preview mode and select macOS as the target, UIKit-related code still gets compiled, leading to a crash, with the error message indicating an issue related to LazyPager's UIKit dependencies. Since it’s not feasible to ask the maintainers of these open-source libraries to add #if canImport(UIKit) conditionals to their code, I would like to ask if there’s a better way to resolve this issue, ensuring that SwiftUI preview works properly on macOS. If you have any suggestions or solutions, I would greatly appreciate your assistance. Thank you so much for your help! import PackageDescription let package = Package( name: "ImportLibrary", platforms: [ .iOS(.v16), .macOS(.v13) ], products: [ .library( name: "ImportLibrary", targets: ["ImportLibrary"]), ], dependencies: [ .package(url: "https://github.com/gh123man/LazyPager", from: "1.1.0"), ], targets: [ .target( name: "ImportLibrary", dependencies: [ "SwiftSoup", "Kingfisher", "WaterfallGrid", .product(name: "LazyPager", package: "LazyPager", condition: .when(platforms: [.iOS])), "QuickModule" ] ), .testTarget( name: "ImportLibraryTests", dependencies: ["ImportLibrary"]), ] ) Sincerely,
Best regards
0
0
247
Sep ’24
refresh the folder icon
Problem Description: I used Swift code to change a folder icon by calling the NSWorkspace.shared.setIcon(_:forFile:options:) method. The specific code is as follows: NSWorkspace.shared.setIcon(coloredIcon, forFile: folderURL.path, options: [.exclude10_4ElementsIconCreationOption]) I noticed that the folder icon has been correctly changed in the Finder preview window, but the icon displayed on the desktop is still the original one. Expected Result: I hope the folder icon on the desktop can also be updated to display the new icon. Solutions Tried: I have tried restarting Finder and manually refreshing the icon cache, but the folder icon on the desktop still does not update. Help Needed: I would like to know if there is a way to automatically refresh the desktop folder icon cache in Swift code to ensure that the changed icon can be immediately displayed.
0
0
366
Jul ’24
SubscriptionStoreView Shows Incorrect Localization
We have configured multi-language support for subscription content in App Store Connect. We are using Apple's provided SubscriptionStoreView from StoreKit to display subscription information. When my Mac system language is set to English or other languages, the localized content within the app displays correctly, but the configuration data fetched by SubscriptionStoreView is always in Chinese. We have reviewed many official documents but have not found a corresponding solution. Since we cannot modify the API within the provided SubscriptionStoreView, even though we have localized and configured accordingly in App Store Connect, users in other language regions cannot view localized content when using our software. The following is the code I referenced from Apple's official demo (Backyard Birds: Building an App with SwiftData and Widgets). @ViewBuilder var subscriptionStoreView: some View { SubscriptionStoreView( groupID: passGroupID, visibleRelationships: .all ) { PassMarketingContent(storeConfigure: storeConfigure) .offset(y:35) .containerBackground(for: .subscriptionStoreFullHeight) { SkyBackground() } } .frame(width: 800, height: 750) .subscriptionStoreControlIcon { _, subscriptionInfo in Group { Image(systemName: "bird") .foregroundColor(.yellow) }.onAppear(perform: { print("subscriptionInfo:\(subscriptionInfo)") }) .foregroundStyle(.black) .symbolVariant(.fill) } #if !os(watchOS) .backgroundStyle(.clear) .subscriptionStoreButtonLabel(.multiline) .subscriptionStorePickerItemBackground(Color(.subscriptionStorePickerItem)) .subscriptionStorePickerItemBackground(.yellow) .storeButton(.visible, for: .policies) .subscriptionStorePolicyDestination(url: URL(string: storeConfigure.storePolicy.privacyPolicy)!, for: .privacyPolicy) .subscriptionStorePolicyDestination(url: URL(string: storeConfigure.storePolicy.termsOfService)!, for: .termsOfService) .subscriptionStorePolicyForegroundStyle(.white) .tint(Color(.blackAppearance)) #endif } This could be due to an API bug, missing configuration, or an issue with the API design itself. I am unsure where to start to solve this problem. Thank you for your help.
1
1
457
Jun ’24