Post

Replies

Boosts

Views

Activity

How does listSectionSpacing works in SwiftUI?
Hello, I want to understand how listSectionSpacing with a custom CGFloat value works in SwiftUI. According to the documentation, we can use different spacing between sections and If adjacent sections have different spacing value, the smaller value on the shared edge is used. For example, if I have a: Section A with a listSectionSpacing of 10 Section B with a listSectionSpacing of 200 Section C with a listSectionSpacing of 20 Section D with a listSectionSpacing of 0 I notice the spacing between the sections A+B and B+C is none of 10, 200 or 20. If the documentation is correct, shouldn't it be 10? If I now have a: Section A with a listSectionSpacing of 200 Section B with a listSectionSpacing of 200 Section C with a listSectionSpacing of 200 Section D with a listSectionSpacing of 0 I notice the spacing is never 200. Is the spacing capped? Also, if I specify a header and footer, the spacing doesn't seem to be used at all. Thus the spacing is the same for all sections. Is my understanding wrong and this API working as expected? Or is that a bug in how the spacing is used? I filed #FB13699952 few weeks ago. Axel struct ListSections: View { @State private var header: Bool = false @State private var footer: Bool = false private let sections: [ListSection] = [ ListSection(position: "A", spacing: 200), ListSection(position: "B", spacing: 200), ListSection(position: "C", spacing: 200), ListSection(position: "D", spacing: 0) ] var body: some View { VStack { Toggle("Header", isOn: $header) Toggle("Footer", isOn: $footer) } .padding(.horizontal) List { ForEach(sections) { section in Section { LabeledContent("Section \(section.position)", value: section.spacing.formatted()) } header: { if header { Text("Header \(section.position)") .background(.red.opacity(0.3)) } } footer: { if footer { Text("Footer \(section.position)") .background(.green.opacity(0.3)) } } .listSectionSpacing(section.spacing) } } } } #Preview { ListSections() }
Topic: UI Frameworks SubTopic: SwiftUI
7
0
1.6k
Jun ’24
Why first View on my NavigationStack appears again when I switch branch?
Hello, In my app, I have an onboarding made of multiple steps in a NavigationStack. I also have a state variable that controls an if else root branch to show either the onboarding NavigationStack or the app content if the onboarding is finished. I noticed that when I end the onboarding (i.e. I switch to the other part of the if else root branch), the onAppear of the first View in the NavigationStack of the onboarding is called again. I don’t understand why. Is this a bug? Thanks, Axel enum Step { case one case two case three case four } struct ContentView: View { @State private var isFinished: Bool = false @State private var steps: [Step] = [] var body: some View { if isFinished { Button("Restart") { steps = [] isFinished = false } } else { NavigationStack(path: $steps) { VStack { Text("Start") .onAppear { print("onAppear: start") } Button("Go to step 1") { steps.append(.one) } } .navigationDestination(for: Step.self) { step in switch step { case .one: Button("Go to step 2") { steps.append(.two) } .onAppear { print("onAppear: step 1") } case .two: Button("Go to step 3") { steps.append(.three) } .onAppear { print("onAppear: step 2") } case .three: Button("Go to step 4") { steps.append(.four) } .onAppear { print("onAppear: step 3") } case .four: Button("End") { isFinished = true } .onAppear { print("onAppear: end") } } } } .onAppear { print("onAppear: NavigationStack") } } } }
6
0
777
Dec ’24
StoreKit 2 - latest transaction for a subscription is not the latest one at launch when app is not running
When dealing with auto-renewable subscriptions, there are multiple ways to access the latest transaction. We can access it when a purchase is made, or we can request the latest transaction for a given productID at a later time. To do so, we can use Transaction.latest(for:), access the transaction history using Transaction.all, get the currentEntitlements, or use the array of Product.SubscriptionInfo.Statusthan contains the latest transaction for a subscription group. It's also necessary to listen to transactions when the app is running using the AsyncSequenceTransaction.updates`. In my app (and also in the SKDemo project from Apple), when I want to access the latest transaction as soon as the app is launched, it's missing the transactions that renewed or happened while the app was not running. I tried using the different methods mentioned above but they never give me the latest transaction, always the latest transaction while the app was running before I killed it. I have to wait for a new renewal event to receive the latest transaction in the Transaction.updates listener, which is not good. For example, when I set the Subscription Renewal Rate to Monthly Renewal Every 30 seconds, and I quit the app when the latest transactionId is 100, I wait for 5 minutes, I expect to see the transactionId 110 but I see 100. In the real life, it means that if the app is not running when a monthly or annual subscription renews, I have to wait weeks or months to receive the missing transaction. I thought that the Transaction.updates listener would be called at launch with all the transactions that occurred while the app was not running. Is that a bug in Xcode or have I misunderstood something? How can I access the real latest transaction that happened when the app was not running at launch? I need to access that to know what the user has access to. I think the transaction management panel from Xcode displays all the transactions, even the one when the app was not running. PS: I'm using Xcode 13.2.1 and iOS 15.0 (simulator). Transaction.updates is not working on iOS 15.2 (my device, or simulator) from what I've seen so far.
5
0
4.3k
Feb ’22
How do subscription promotional offers work for currently subscribed customers?
Hello, I'm trying to understand what happens when a subscribed customer of a subscription A purchases a promotional offer for the same subscription A. Let's say the product is a yearly subscription priced at $100. When the month 7 starts (6 months remaining in the regular subscription period), I send the user a promotional offer for the same product but priced at $25 for the first year (100$ afterwards) and he accepts the offer. Is the promotional offer started only at the end of the current year (after the 6 remaining months) or is it started immediately and he gets a pro-rata refund for the 6 remaining months? Thanks.
5
0
942
Sep ’25
Calendar nextDate/enumerateDates methods with backward direction does not work for September
I’m trying to get the previous date that matches the 9nth month in the Gregorian calendar (which is September) from Date.now (which is in December 2023 right now). The expected date is then in 2023. The first date returned is in 1995. Why? I filed the feedback FB13462533 var calendar: Calendar = Calendar(identifier: .gregorian) calendar.timeZone = TimeZone.autoupdatingCurrent let matchingDateComponents: DateComponents = DateComponents(month: 09) let date: Date? = calendar.nextDate( after: Date.now, matching: matchingDateComponents, matchingPolicy: .nextTime, direction: .backward ) print(date) // Optional(1995-08-31 23:00:00 +0000)
4
0
730
Dec ’23
SwiftUI: detect the beginning of a View using scrollPosition in a V/HStack
Hello, I want to detect when a ScrollView is scrolled at the top of a specific View in a LazyVStack. Here is the code I use: struct ContentView: View { @State private var scrollID: Int? var body: some View { HStack { VStack { Text(scrollID?.formatted() ?? "Unknown") Button("Go") { withAnimation { scrollID = 7 } } Divider() ScrollView { LazyVStack(spacing: 300) { ForEach(0...100, id: \.self) { int in Text(int.formatted()) .frame(maxWidth: .infinity) .background(.red) } } .scrollTargetLayout() } .scrollPosition(id: $scrollID, anchor: .top) } } } } As I specify a top anchor, I was expecting to see the scrollID binding being updated when the red Text View is at the top of the ScrollView. But I noticed that scrollPosition updates the binding way before the red Text View is positioned at the top of the ScrollView, which is not what I want. In this image, you can see the binding is already at one even though there is a lot of space between the View and the top of the ScrollView. Maybe the Stack spacing is taken into account? And manually setting the binding scroll at the position I want, just above the red Text for 7, which makes me think the views IDs are correct. Is my understanding wrong about this modifier? How can I detect the top (beginning) of the View? (If this is a SwiftUI bug, I filed #FB13811349)
4
0
2.7k
Jun ’24
Clear Purchase History for a Sandbox Apple ID doesn't work
Hello, I'm trying to clear the purchase history made with a sandbox Apple ID on my test device but it does not work. The past purchases are still returned by StoreKit. I've waited many hours but it seems to persist. When I use for await result in Transaction.currentEntitlements { in my app, my non-consumable product is still here. Is it expected? How long should it take to reset the history? Is is supposed to work also for non-consumable products? Thanks Axel
4
10
1.1k
Sep ’24
Adding an entity to a Core Data model prevent Canvas Preview to show
Hello, I have a SwiftUI application with a Core Data model. This model contains some entities, with properties. The canvas is working as expected, showing the preview. But whenever I add a new entity, event without any property, the canvas fail to show the preview (event a basic view with only a text view in it). The error message is the following: Cannot preview in this file - The operation couldn't be completed. Transaction failed. Process failed to launch. I tried to clean my cache, the derived data folder, reset the simulators, etc. When I click on Diagnostics, here is the message: Error Domain=FBProcessExit Code=4 "The process crashed." UserInfo={NSLocalizedFailureReason=The process crashed., BSErrorCodeDescription=crash, NSUnderlyingError=0x600002f29dd0 {Error Domain=signal Code=4 "SIGILL(4)" UserInfo={NSLocalizedFailureReason=SIGILL(4)}}} RemoteHumanReadableError: The operation couldn’t be completed. Transaction failed. Process failed to launch. (process launch failed) BSTransactionError (1): ==error-description: Process failed to launch. ==precipitating-error: Error Domain=FBProcessExit Code=4 "The process crashed." UserInfo={NSLocalizedFailureReason=The process crashed., BSErrorCodeDescription=crash, NSUnderlyingError=0x600002f29dd0 {Error Domain=signal Code=4 "SIGILL(4)" UserInfo={NSLocalizedFailureReason=SIGILL(4)}}} ==NSLocalizedFailureReason: Transaction failed. Process failed to launch. (process launch failed) ==transaction: <FBApplicationProcessLaunchTransaction: 0x60000186d960> ==error-reason: process launch failed Any idea why I have that? Thanks, Axel PS: I'm using Xcode 12 beta 6 (also tried on beta 5). I'm on macOS Big Sur (20A5364e).
3
0
2.0k
Dec ’20
SignInWithAppleButton not found in scope (SwiftUI 2)
Hello, I'm implementing Sign In With Apple in a SwiftUI application (iOS 14, SwiftUI 2). I'm importing the AuthenticationServices framework. The app build successfully, and can run on an iOS device or simulator. But I cannot preview the view in the Preview / Canvas (it would be easier to design the view). Cannot find 'SignInWithAppleButton' in scope Any idea why? Thanks Axel PS: Xcode 12 beta 6, macOS Big Sur beta 5
3
0
1.8k
Nov ’21
StoreKit 2 • updateListenerTask never called (Ask To Buy context for example)
Hello, I'm currently adding StoreKit 2 into my app. I've watched the WWDC21 session (Meet SK2) and downloaded the sample SKDemo app. When I want to test the Ask To Buy flow, it does not work: I see the sheet on the device, I see the alert and tap on the "Ask" button. In Xcode, I then approve the transaction but the func listenForTransactions() -> Task<Void, Error> is never called. I'm testing the app in Debug mode, on a real device and on a simulator (using the Products.storekit local configuration file). What's wrong? Thanks, Axel Version 13.2 beta 2 (13C5081f) iOS 15.2 (19C5044b) func listenForTransactions() -> Task<Void, Error> {         return Task.detached {             for await result in Transaction.updates {                 do {                     let transaction = try self.checkVerified(result)                     await self.updatePurchasedIdentifiers(transaction)                     await transaction.finish()                 } catch {                     print("Transaction failed verification")                 }             }         }     }
3
0
2.6k
Mar ’22
NavigationSplitView crashes if I select an item in the sidebar after I removed other items
My NavigationSplitView crashes if I select an item in the sidebar after I removed other items: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1c44d488c) How to reproduce: Launch the app from the attached project: https://gist.github.com/alpennec/a45f5ff94382dc922718906a60a35220 Tap on “Add” Select the new added item in the sidebar In the detail view, tap “Delete” Select “All” in the sidebar The app crashes: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1c44d488c) It occurs if I use just Strings or Core Data objects (I tried with plain String because I thought it was maybe an issue with Core Data but it’s not apparently). What is wrong? Is that a bug? Filed #FB13561900 for this.
3
0
847
Jan ’24
Bug in Screen Time API: familyActivityPicker dismisses a presenting sheet on iOS 18.4 and above
Hello, I’m presenting the familyActivityPicker from a presented sheet in my application. When I select some apps, categories or websites and tap “Done”, the familyActivityPicker is dismissed but the presenting sheet is also dismissed on iOS 18.4, iOS 18.5, iOS 26 beta 1 and 2. If I tap on “Cancel” from the familyActivityPicker, the sheet is also dismissed on iOS 18.4, iOS 18.5, iOS 26 beta 1 and 2. The same code works perfectly fine on iOS 18.0, iOS 18.1, iOS 18.2 and iOS 18.3. Is this a known-issue? If opened the feedback FB18369821 for this. Regards, Axel
3
0
138
Aug ’25
StoreKit 2 • How to know when a user cancelled the subscription during free trial?
Hello, When a user cancels a subscription during a free trial, we should stop providing access to content. How can we know that? From the in app management in Xcode, when I cancel a subscription during free trial period (cancelling in the few seconds after the purchase), the currentEntitlements still provide the subscription. How to know when a user cancelled the subscription during free trial? Thanks
2
0
2.7k
Nov ’21
StoreKit 2: how can we test Family Sharing?
I'm not a member of any Family in iCloud. I want to understand what happens when a user is subscribed through Family Sharing but also how to use StoreKit when the user is subscribed twice: as an individual who purchased the product and as a member of a family when the purchase is shared with him. How can I test Family Sharing for an app offering a product with Family Sharing enabled? Is it possible to create a fake Family in App Store Connect and add testers to it?
2
0
1.9k
Dec ’21