When using SwiftUI Previews in a Swift Packages, are PreviewProviders automatically removed from the package when archiving an app, as it is the case with a app, or not?
If not, how to deal with that?
I’m not sure we can use compiler directives like if DEBUG in packages, can we?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I want to animate part of my View when a property on a Core Data object is updated. These Core Data objects are ObservableObject so when I update a property on the object using a binding (like a Toggle) or a Button, I expect it to animate. But it’s not working. If I toggle a boolean property on my object, there is no animation. If I change a Boolean value in a Button using a withAnimation block, it does not animated. If I do the same with an ObservableObject class (boolean is a Published property), the animation is respected. A workaround is to use another property (isFavoriteWrapped) and to call objectWillChange.send() manually in the property setter. But this feels wrong. The expected behaviour should be similar to what we see with the ObservableObject.
I opened a FB12174214.
See attached screenshots.
How can this design be reproduced in SwiftUI?
The capsules are positioned to represent the values. But the calculation needs to take into account the labels width.
I tried using a mix of Grid and custom Layout but I haven’t found a way… Any help would be appreciated!
Thanks
In UIKit, we can add an insets to a MKMapView with setVisibleMapRect to have additional space around a specified MKMapRect. It's useful for UIs like Apple Maps or FlightyApp (see first screenshot attached). This means we can have a modal sheet above the map but still can see all the content added to the map.
I'm trying to do the same for a SwiftUI Map (on iOS 17) but I can't find a way to do it: see screenshot 2 below. Is it possible to obtain the same result or should I file a feedback for an improvement?
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?
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)
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.
I'm creating an app that uses WeatherKit to get weather data. I wanted to confirm if the requests made to the service during app development will be deducted from our monthly usage limit or credit?
Thanks
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)
Hello,
I include a Privacy Manifest file in my app and specify one Privacy Nutrition Label Type (Email Address, for marketing purposes). My app uses some third-party SDKs like RevenueCat that contain Privacy Manifest files with nutrition label types specified (Purchases History for RevenueCat for example).
Xcode can generate a report that aggregates all the data types that are collected by the app.
But is App Store Connect updated when I upload a build? Or do I have to manually setup the App Privacy info?
Thanks
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
App Store Connect
Privacy
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
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
Hello,
I'm trying to create a subscription for one of my apps.
When I specify the Product ID yearly_3, I get the following error message: The Product ID you entered is already being used by another subscription.
This app does not have any other subscriptions with this Product ID.
But I have another app with a yearly_3 Product ID.
According to the official documentation, the Product ID is A unique ID specific to your app. So I thought it was possible to have the same Product ID between apps, but not for the same app.
What's the rule here?
Thanks,
Axel
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
Subscriptions
App Store Connect
In-App Purchase
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
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect API
Tags:
App Store
App Store Connect
App Store Connect API
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
Topic:
App & System Services
SubTopic:
General
Tags:
SwiftUI
Family Controls
Managed Settings
Screen Time