Post

Replies

Boosts

Views

Activity

SwiftUI toolbar with IDs crash since macOS 15
I understand this is a known issue, but it’s truly unacceptable that it remains unresolved. Allowing users to customize toolbars is a fundamental macOS feature, and it has been broken since the release of macOS 15. How is it possible that this issue persists even in macOS 15.3 beta (24D5040f)? FB15513599 import SwiftUI struct ContentView: View { @State private var showEditItem = false var body: some View { VStack { VStack { Text("Instructions to reproduce the crash") .font(.title) .padding() Text(""" 1. Click on "Toggle Item" 2. In the menu go to File > New Window 3. In new window, click on "Toggle Item" """) } .padding() Button { showEditItem.toggle() } label: { Text("Toggle Item") } } .padding() .toolbar(id: "main") { ToolbarItem(id: "new") { Button { } label: { Text("New…") } } if showEditItem { ToolbarItem(id: "edit") { Button { } label: { Text("Edit…") } } } } } }
5
3
565
3w
Preventing animation glitch when dismissing a Menu with glassEffect
Hi everyone, I’m running into a strange animation glitch when using a Menu inside a glassEffect container. Here’s a minimal example: import SwiftUI struct ContentView: View { @Namespace private var namespace var body: some View { ZStack { Image(.background) .resizable() .frame(maxWidth: .infinity, maxHeight: .infinity) .ignoresSafeArea() GlassEffectContainer { HStack { Button("b1") {} Button("b2") {} Button("b3") {} Button("b4") {} Button("b5") {} Menu { Button("t1") { } Button("t2") { } Button("t3") { } Button("t4") { } Button("t5") { } } label: { Text("Menu") } } } .padding(.horizontal) .frame(height: 50) .glassEffect() } } } What happens: The bar looks fine initially: When you open the Menu, the entire bar morphs into the menu: When dismissing, the bar briefly animates into a solid rectangle before reapplying the glass effect: Questions: Is there a way to prevent that brief rectangle animation when dismissing the menu? If not, is it possible to avoid the morphing altogether and have the menu simply overlay on top of the bar instead of replacing it? Any ideas or workarounds would be greatly appreciated!
1
1
356
Sep ’25
Glass effect on a stroke
I'm trying to apply a glass effect on a circle stroke but all it does is apply it to the circle itself and not the stroke: import SwiftUI let kCarouselCircleSize: CGFloat = 150 let kCarouselOpacity: Double = 0.3 let kCarouselStrokeWidth: CGFloat = 60 struct ContentView: View { @State var showing = false var body: some View { VStack(spacing: 60) { Text("ultraThinMaterial:") .font(.title) CarouseCircle(drawProgress: 0.7, isActive: false) Text("glassEffect()") .font(.title) CarouseCircle(useGlassEffect: true, drawProgress: 0.7, isActive: false) } .background(content: { Image(.background2) }) .padding() } } struct CarouseCircle: View { var size: CGFloat = kCarouselCircleSize var strokeWidth: CGFloat = kCarouselStrokeWidth var useGlassEffect: Bool = false var drawProgress: CGFloat var isActive: Bool var body: some View { if useGlassEffect { Circle() .trim(from: 0, to: drawProgress) .fill(.clear) .stroke(.blue, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round)) .frame(width: size, height: size) .glassEffect() .shadow(color: .black.opacity(kCarouselOpacity), radius: isActive ? 4 : 1, x: 0, y: 0) .rotationEffect(.degrees(-90)) // Start drawing at button 1's position } else { Circle() .trim(from: 0, to: drawProgress) .fill(.clear) .stroke(.ultraThinMaterial, style: StrokeStyle(lineWidth: strokeWidth, lineCap: .round)) .frame(width: size, height: size) .shadow(color: .black.opacity(kCarouselOpacity), radius: isActive ? 4 : 1, x: 0, y: 0) .rotationEffect(.degrees(-90)) // Start drawing at button 1's position } } } Here's the result: Is this supported, a bug or something I'm doing wrong?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
0
157
Jul ’25
Allow custom tap gesture in List but maintain default selection gesture
I'm trying to create a List that allows multiple selection. Each row can be edited but the issue is that since there's a tap gesture on the Text element, the list is unable to select the item. Here's some code: import SwiftUI struct Person: Identifiable { let id: UUID let name: String init(_ name: String) { self.id = UUID() self.name = name } } struct ContentView: View { @State private var persons = [Person("Peter"), Person("Jack"), Person("Sophia"), Person("Helen")] @State private var selectedPersons = Set<Person.ID>() var body: some View { VStack { List(selection: $selectedPersons) { ForEach(persons) { person in PersonView(person: person, selection: $selectedPersons) { newValue in // ... } } } } .padding() } } struct PersonView: View { var person: Person @Binding var selection: Set<Person.ID> var onCommit: (String) -> Void = { newValue in } @State private var isEditing = false @State private var newValue = "" @FocusState private var isInputActive: Bool var body: some View { if isEditing { TextField("", text: $newValue, onCommit: { onCommit(newValue) isEditing = false }) .focused($isInputActive) .labelsHidden() } else { Text(person.name) .onTapGesture { if selection.contains(person.id), selection.count == 1 { newValue = person.name isEditing = true isInputActive = true } } } } } Right now, you need to tap on the row anywhere but on the text to select it. Then, if you tap on the text it'll go in edit mode. Is there a way to let the list do its selection? I tried wrapping the tap gesture in simultaneousGesture but that didn't work. Thanks!
3
2
1.9k
Feb ’25
@Observable and didSet?
I'm in the process of migrating to the Observation framework but it seems like it is not compatible with didSet. I cannot find information about if this is just not supported or a new approach needs to be implemented? import Observation @Observable class MySettings { var windowSize: CGSize = .zero var isInFullscreen = false var scalingMode: ScalingMode = .scaled { didSet { ... } } ... } This code triggers this error: Instance member 'scalingMode' cannot be used on type 'MySettings'; did you mean to use a value of this type instead? Anyone knows what needs to be done? Thanks!
11
3
4.6k
Jan ’25
Keyboard will not show when setting focus on a SwiftUI text field from a button in an ornament on visionOS
Using a button that is placed in the bottom ornament to set focus on a text field will not display the keyboard properly while a button embedded in the view will behave as expected. To demonstrate the issue, simply run the attached project on Vision Pro with visionOS 1.1 and tap the Toggle 2 button in the bottom ornament. You’ll see that the field does have focus but the keyboard is now visible. Run the same test with Toggle 1 and the field will get focus and the keyboard will show as expected. import SwiftUI import RealityKit import RealityKitContent struct ContentView: View { @State private var text = "" @State private var showKeyboard = false @FocusState private var focusedField: FocusField? private enum FocusField: Hashable { case username case password } var body: some View { VStack { TextField("Test", text: $text) .focused($focusedField, equals: .username) Text("Entered Text: \(text)") .padding() Button("Toggle 1") { // This button will work and show the keyboard if focusedField != nil { focusedField = nil } else { focusedField = .username } } Spacer() } .padding() .toolbar { ToolbarItem(placement: .bottomOrnament) { Button("Toggle 2") { // This button will set focus properly but not show the keyboard if focusedField != nil { focusedField = nil } else { focusedField = .username } } } } } } Is there a way to work around this? FB13641609
1
0
756
Jan ’25
Cannot redeem offer codes on Mac App Store, works fine on App Store.
It appears there's an issue with the Mac App Store's ability to process offer codes, unlike its iOS counterpart, which handles them seamlessly. Users attempting to redeem a code on their Mac are encountering a "Cannot redeem code. Try another code" error. Considering the Mac App Store's long history, having been introduced nearly 13 years ago, it's high time for it to align with the iOS App Store's functionality. While it's close to 80% there, addressing these lingering issues would greatly improve the user experience. FB13463658
2
3
1.1k
Jan ’25
Set filename to use for "Save to Files" with ShareLink?
Isn't there no way to set the default filename to use when we want to save a DataRepresentation to a file? If I export to JSON, the filename is "JSON.json" is used by iOS, even if I set the name to use in SharePreview. struct ContentView: View {     let car = Car(id: UUID(), name: "911", items:                     [Item(id: UUID(),date: .now, desc: "oil change"),                      Item(id: UUID(),date: .now, desc: "Battery")])     var body: some View {         VStack {             ShareLink(item: car, preview: SharePreview(car.name))         }         .padding()     } } extension UTType {     static var car: UTType = UTType(exportedAs: "com.acme.cararchive") } struct Car: Codable {     let id: UUID     let name: String     let items: [Item] } extension Car: Transferable {     static var transferRepresentation: some TransferRepresentation {         DataRepresentation(contentType: .json) { archive in             try JSONEncoder().encode(archive)         } importing: { data in             try JSONDecoder().decode(Car.self, from: data)         }     } } struct Item: Codable {     let id: UUID     let date: Date     let desc: String }
4
0
2.6k
Nov ’24
Product.SubscriptionInfo.Status is empty despite having valid subscription.
I don't know if this is a iOS 18.1 beta bug or some StoreKit server issues but Product.SubscriptionInfo.Status is returning an empty array in production even if the user has a valid subscription that is months away from expiring or renewing. I myself ran into this issue this morning but of course everything is fine in development mode so that makes it quite challenging to debug. Anyone else has this issue?
2
1
571
Oct ’24
Swift compiler crash with Xcode 16 beta 5
This simple project just makes the Swift compiler crash in init(comparator: KeyPathComparator<RemoteComputer>): import SwiftUI struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() } } enum CSItemOrderType: Int, Codable, CaseIterable, CustomStringConvertible { case readableName case lastConnectionDate case numberOfConnections var description: String { switch self { case .readableName: return "STR_NAME" case .lastConnectionDate: return "STR_LAST_CONN_DATE" case .numberOfConnections: return "STR_ORDER_MOST_CONNECTED" } } } struct CSItemOrder: Codable { static let allCases = [CSItemOrder(type: .readableName), CSItemOrder(type: .lastConnectionDate, order: .reverse), CSItemOrder(type: .numberOfConnections, order: .reverse)] static let allSortOrders = [KeyPathComparator(\RemoteComputer.readableName), KeyPathComparator(\RemoteComputer.lastConnectionDate), KeyPathComparator(\RemoteComputer.numberOfConnections)] let type: CSItemOrderType var order: SortOrder var comparator: KeyPathComparator<RemoteComputer> { switch type { case .readableName: return KeyPathComparator(\RemoteComputer.readableName, order: order) case .lastConnectionDate: return KeyPathComparator(\RemoteComputer.lastConnectionDate, order: order) case .numberOfConnections: return KeyPathComparator(\RemoteComputer.numberOfConnections, order: order) } } init(type: CSItemOrderType, order: SortOrder = .forward) { self.type = type self.order = order } init(comparator: KeyPathComparator<RemoteComputer>) throws { switch comparator.keyPath { case \RemoteComputer.readableName: self.init(type: .readableName, order: comparator.order) case \RemoteComputer.lastConnectionDate: self.init(type: .lastConnectionDate, order: comparator.order) case \RemoteComputer.numberOfConnections: self.init(type: .numberOfConnections, order: comparator.order) default: print("Unsupported keyPath: \(comparator.keyPath)") throw ItemOrderError.unsupportedKeyPath } } } struct RemoteComputer: Codable, Hashable, Identifiable { let id: Int let name: String let hostname: String? let localIpAddress: String? let vncPort: Int let sshPort: Int let publicIpAddress: String? let publicPort: Int let macAddress: String let scVersion: String let manualMode: Int let uuid: String let lastMappingStatus: String? let isAwake: Bool let unregistered: Bool let osVersion: String? let lastUpdate: Date let remoteAddress: String? let lastKeyboardLocale: String? let macSystemShortcuts: [String: [Int32]]? var readableName: String { return name.removingPercentEncoding ?? name } var lastConnectionDate: Date { return Date.now } var unwrappedPublicIpAddress: String { return publicIpAddress ?? NSLocalizedString("STR_NOT_AVAILABLE", comment: "") } var numberOfConnections: Int { return 0 } } enum ItemOrderError: Error { case unsupportedKeyPath } This code works fine in previous betas or Xcode 15.
4
1
945
Aug ’24
Search Ads (Basic) campaign stopped at previous budget even if it was raised during the month.
I raised the monthly budget for this app from $1300 to $2000 during July, but the campaign stopped once it reached $1303.84 around July 21st. I understand that lowering the budget should only apply in the following month, so why did the campaign stop even though there was roughly $700 left for the month? The issue is that the system spent the initial budget within three weeks as if it was using the new budget, so I don't have ads showing for the remainder of the month. The CPI is set at $5.60 per recommendation, and the average CPI is $1.28, so I don't think the issue is that the bid is not high enough.
1
0
634
Jul ’24
Toolbar buttons disappearing when showing a navigation split view as a sheet
When displaying a view using a navigation Split View as a sheet, the toolbar button will disappear if you leave the app and resume it. import SwiftUI struct Folder: Hashable, Identifiable { let id = UUID() let name: String } struct ContentView: View { @State private var showingSettings = false var body: some View { VStack { Button { showingSettings.toggle() } label: { Text("Settings") } } .sheet(isPresented: $showingSettings, content: { SettingsView() }) .padding() } } struct SettingsView: View { @Environment(\.dismiss) private var dismiss @State private var selectedFolder: Folder? = nil private var folders = [Folder(name: "Recents"), Folder(name: "Deleted"), Folder(name: "Custom")] var body: some View { NavigationSplitView { SidebarView(selectedFolder: $selectedFolder, folders: folders) } detail: { VStack { if let folder = selectedFolder { Text(folder.name) } else { Text("No selection") } } .toolbar { ToolbarItem(placement: .cancellationAction) { Button { dismiss() } label: { Text("Cancel") } } ToolbarItem(placement: .confirmationAction) { Button { dismiss() } label: { Text("Save") } } } } } } struct SidebarView: View { @Binding var selectedFolder: Folder? var folders: [Folder] var body: some View { List(selection: $selectedFolder) { ForEach(folders) { folder in NavigationLink(value: folder) { Text(folder.name) } } } } } Steps to reproduce the issue: Launch the attached project on an iPad or iPad simulator Tap the Settings button Select one item in the sidebar Use the app switcher to open an other app or just leave the app Bring back the app Result: Both Cancel and Save buttons are gone. Note: This will not occur if no item is selected in the sidebar. FB12991687
4
0
1.9k
Jul ’24