Post

Replies

Boosts

Views

Activity

In Swift, how can I get the "last Sunday of a month before the current date"?
I want to find the "last Sunday of a month before the current date" in Swift, but using the Calendar nextDate function doesn't work (always returns nil). var calendar: Calendar = Calendar(identifier: .gregorian) calendar.timeZone = .gmt let lastSundayDateComponents: DateComponents = DateComponents( weekday: 1, weekdayOrdinal: -1 ) let previousLastSundayDate: Date? = calendar.nextDate( after: Date.now, matching: lastSundayDateComponents, matchingPolicy: .nextTime, repeatedTimePolicy: .first, direction: .backward ) print(previousLastSundayDate ?? "Not found") // "Not found" If I use a positive weekdayOrdinal, it's working normally and the same nextDate method provides the correct date. let firstSundayDateComponents: DateComponents = DateComponents( weekday: 1, weekdayOrdinal: 1 ) When I check if the date components can provide a valid date for the given calendar, it returns false... let lastSundayInNovember2023DateComponents: DateComponents = DateComponents( year: 2023, month: 11, weekday: 1, weekdayOrdinal: -1 ) // THIS RETURNS FALSE let isValid: Bool = lastSundayInNovember2023DateComponents.isValidDate(in: calendar) print(isValid) // false ... even if the correct date can be created. let lastSundayInNovember2023: Date = calendar.date(from: lastSundayInNovember2023DateComponents)! print(lastSundayInNovember2023) // 2023-11-26 00:00:00 +0000 Is that a bug in Foundation?
2
0
1k
Dec ’23
What are possible failures when using CLLocationUpdate.Updates AsyncSequence
Hello, I'm currently migrating my app location service to use the new CLLocationUpdate.Updates. I'm trying to understand what can fail in this AsyncSequence. Based on the previous CLError, I thought authorisation was one of them for example but it turns out that this is handled by the CLLocationUpdate where we can check different properties. So, is there a list of errors available somewhere? Thanks Axel, @alpennec
2
0
444
Dec ’24
App Store Connect API: Modify an Auto-Renewable Subscription to change prices for all territories
Hello, I want to update the prices in all territories of an auto-renewable subscription at once (in a single request). I know it's possible to do it territory by territory using the Create a Subscription Price Change API endpoint, but this means I need to call this API for every territory. And I have a lot of subscriptions I need to update. There is an another API endpoint that seems to allow to Modify an Auto-Renewable Subscription. For the countries where I want to change the price, I fetch the subscription price points using the List All Price Points for a Subscription API endpoint. When I call this API endpoint with the following body (that is the expected body content for this endpoint): { "data": { "type": "subscriptions", "relationships": { "prices": { "data": [ { "id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJDQU4iLCJwIjoiMTAwMDEifQ", "type": "subscriptionPrices" }, { "type": "subscriptionPrices", "id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJVU0EiLCJwIjoiMTAwMDEifQ" } ] } }, "id": "6740021496" }, "included": [ { "relationships": { "subscriptionPricePoint": { "data": { "id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJDQU4iLCJwIjoiMTAwMDEifQ", "type": "subscriptionPricePoints" } }, "territory": { "data": { "type": "territories", "id": "CAN" } }, "subscription": { "data": { "id": "6740021496", "type": "subscriptions" } } }, "id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJDQU4iLCJwIjoiMTAwMDEifQ", "attributes": { "preserveCurrentPrice": true }, "type": "subscriptionPrices" }, { "attributes": { "preserveCurrentPrice": true }, "id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJVU0EiLCJwIjoiMTAwMDEifQ", "type": "subscriptionPrices", "relationships": { "subscription": { "data": { "type": "subscriptions", "id": "6740021496" } }, "subscriptionPricePoint": { "data": { "type": "subscriptionPricePoints", "id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJVU0EiLCJwIjoiMTAwMDEifQ" } }, "territory": { "data": { "type": "territories", "id": "USA" } } } } ] } I receive a 409 error: { "errors" : [ { "id" : "5b6a4b62-686c-4a65-87ba-e16131db517b", "status" : "409", "code" : "ENTITY_ERROR", "title" : "There is a problem with the request entity", "detail" : "User is not allowed to edit.", "source" : { "pointer" : "subscriptionPrices" } } ] } I made sure my bearer authorisation token is correct and still valid (not expired). the p8 key has Admin rights Can this PATCH endpoint be used for what I want to do? If yes, is there anything special to do to use this PATCH endpoint? Thanks, Axel
2
0
599
Jan ’25
How can I remove a localization from a String Catalog in a Swift Package?
Hello, I'm trying to remove a localization from a String Catalog in a Swift Package. How can I do that? I tried to remove the file and create a new one, but all the languages are back. The only place where I've found a reference to the languages is in Package/.swiftpm/xcode/package.xcworkspace/xcuserdata/user.xcuserdatad/UserInterfaceState.xcuserstate But I don't know how to edit this file to remove a language. Thank you, Axel
2
0
153
Oct ’25
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
848
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
140
Aug ’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
732
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
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
946
Sep ’25
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
779
Dec ’24