Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

Implement Continuity Markup in Mac app?
Hello, is there a way to implement Continuity Markup in our own apps? (This is what I'm talking about: https://support.apple.com/en-us/102269 , scroll down to "Use Continuity Markup"). Also, why does a QuickLook panel (QLPreviewPanel.shared()) not display the markup options when triggered from my app for png image files in my app's Group Container? Do I need to implement certain NSServicesMenuRequestor methods for that? Sadly, I could not find any docs on that. Thank you, – Matthias
0
0
127
Apr ’25
Animating Text foregroundStyle with gradients
Hello! We can animate Text color via foregroundStyle very nicely in SwiftUI like so: Text("Some text here") .foregroundStyle(boolValue ? Color.green : Color.blue) withAnimation { boolValue.toggle() } However, if the foregroundStyle is a gradient, the color of the Text view changes immediately without animation. The code below works to animate a gradient foregroundStyle on an SF Symbol, but it does not work when applied to a Text view. Is it possible to animate a Text view foregroundStyle between gradient values? Image(systemName: "pencil.circle.fill") .foregroundStyle(boolValue ? .linearGradient(colors: [.red, .orange], startPoint: .top, endPoint: .bottom) : .linearGradient(colors: [.green, .blue], startPoint: .top, endPoint: .bottom)) Thanks for your help!
1
0
337
Mar ’25
Live Activity resets to initial state after 8+ hours in background
Hi Apple team and community, We’re encountering a strange issue with Live Activity that seems related to memory management or background lifecycle. ❓ Issue: Our app updates a Live Activity regularly (every 3 minutes) using .update(...). However, after the app remains in the background for around 8 hours, the Live Activity reverts to the initial state that was passed into .request(...). Even though the app continues sending updates in the background, the UI on the Lock Screen and Dynamic Island resets to the original state.
0
0
68
Apr ’25
UINavigationController inside singleton
I have a struct that holds an instance of UINavigationController: struct NavigationController { static let shared = UINavigationController() } I use NavigationController.shared to push and pop ViewControllers around the app, rather than using the ViewController's .navigationController property. The issue I'm having is that when I pop I get new instances of my previous ViewController, this is my hierarchy: (0) UIWindow | ---- (1) NavigationController (is set as the UIWindow.rootViewController) | ---- (2) UITabBarController (is set with NavigationController.shared.setViewControllers) | ---- (3) ViewController (HomeVC) (is the first tab of the UITabController) | ---- (4) ViewController (ScanVC) (is pushed into the stack by NavigationController.shared.pushViewController) ---- (5) ViewController (NotificationsVC) ---- (6) ViewController (SettingsVC) I put a print statement in my HomeVC in the viewDidLoad method My understanding is that the viewDidLoad should only be called once in the lifecycle of a ViewController When I go back to the HomeVC from the ScanVC then the print always gets triggered which means I have a new instance of the HomeVC This is the print statement I created inside the viewDidLoad method: print("\(#function) View Did Load, instance: \(self)") Here's the output from going back and forth from the HomeVC to ScanVC: viewDidLoad() View Did Load, instance: <HomeVC: 0x118db0000> viewDidLoad() View Did Load, instance: <HomeVC: 0x118db3100> viewDidLoad() View Did Load, instance: <HomeVC: 0x118db0700> Any one has any suggestions on how to fix this? Because ideally going back to the HomeVC should not instantiate a new ViewController. I tested this on a small test project and viewDidLoad would only be triggered once when the ViewController was instantiated.
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
253
Mar ’25
MapKit causing TabBar Overwrite
Hi everyone! I am having a bit of trouble with why my Map() is overwriting my customized tabBar settings. Specifically my tab bar background. (White -> Black) Map(position: $cameraPosition) { UserAnnotation() } .toolbarBackground(.hidden, for: .tabBar) This above ^ is a view which acts as a tab view for my tab bar. I have customized my tab bar as follows just so it was obvious to see me changes. let tabAppearance = UITabBarAppearance() tabAppearance.configureWithOpaqueBackground() tabAppearance.backgroundColor = .white UITabBar.appearance().standardAppearance = tabAppearance UITabBar.appearance().scrollEdgeAppearance = tabAppearance I have tried implementing solutions which is seen with my .toolbar attempt but nothing has help. I would like the tab bar to be consistent with all of my views and from my understanding the Map is overwriting those settings.
1
0
63
Apr ’25
SwiftData crash when using a @Query on macOS 15.3.x
We use @Query macro in our App. After we got macOS 15.3 update, our App crashes at @Query line. SwiftData/Schema.swift:305: Fatal error: KeyPath \Item.<computed 0x0000000100599e54 (Vec3D)>.x points to a field (<computed 0x0000000100599e54 (Vec3D)>) that is unknown to Item and cannot be used. This problem occurs only when the build configuration is "Release", and only when I use @Query macro with sort: parameter. The App still works fine on macOS 14.7.3. This issue seems similar to what has already been reported in the forum. It looks like a regression on iOS 18.3. https://developer.apple.com/forums/thread/773308 Item.swift import Foundation import SwiftData public struct Vec3D { let x,y,z: Int } extension Vec3D: Codable { } @Model final class Item { var timestamp: Date var vec: Vec3D init(timestamp: Date) { self.timestamp = timestamp self.vec = Vec3D(x: 0, y: 0, z: 0) } } ContentView.Swift import SwiftUI import SwiftData struct ContentView: View { @Environment(\.modelContext) private var modelContext @Query(sort: \Item.vec.x) // Crash private var items: [Item] var body: some View { NavigationSplitView { List { ForEach(items) { item in NavigationLink { Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))") } label: { Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard)) } } .onDelete(perform: deleteItems) } .navigationSplitViewColumnWidth(min: 180, ideal: 200) .toolbar { ToolbarItem { Button(action: addItem) { Label("Add Item", systemImage: "plus") } } } } detail: { Text("Select an item") } } private func addItem() { withAnimation { let newItem = Item(timestamp: Date()) modelContext.insert(newItem) } } private func deleteItems(offsets: IndexSet) { withAnimation { for index in offsets { modelContext.delete(items[index]) } } } }
1
0
475
Feb ’25
UITabbarController issue on iOS 18
I'm building an app using UITabbarController with 2 tabs: screen A and B. When standing on tab B and I taps on tab A, the order in which the events are triggered will be: For iOS < 18: viewWillDisappear() of screen B tabBarController(_:didSelect:) of UITabbarController For iOS >= 18: tabBarController(_:didSelect:) of UITabbarController viewWillDisappear() of screen B So my question is this an issue or a new update from Apple on iOS 18.*?
Topic: UI Frameworks SubTopic: UIKit Tags:
2
0
395
Mar ’25
Serious Bug with SwiftUI/ImagePicker/Camera + workaround
I was doing an app which had several "camera" buttons each one dedicated to taking/storing/reviewing/deleting an image associated with a variable URL but what should have been a simple no brainer turned out to be a programming nightmare. To cut a long story short there is a bug in the sheet handling wherebye even tho you have separate instance for each button the camera/picker cylcles sequentially thru the stack of instances for any action finally always placing the image in the first URL. Working with myself debugging, all major AIs (Grok, Claude, Gemini and Perplexity) after 4 x 12hr+ days we finally managed to crack a solution. What follows is Groks interpretation (note it misses the earlier problem of instance cycling!!) ... You can follow the discussion here: https://x.com/i/grok/share/KHeaUPladURmbFq5qy9W506er but be warned its long a detailed but if you are having problems then read ... **Bug Report: Race Conditions with UIImagePickerController in SwiftUI Sheet ** Environment: SwiftUI, iOS 17.7.5 Device: iPad Pro (12.9-inch, 2nd generation) Xcode Version: [Insert your Xcode version] Date: March 30, 2025 **Issue 1: Multiple Instances of UIImagePickerController Spawned After Dismissal ** Description: When using a UIImagePickerController wrapped in a UIViewControllerRepresentable and presented via a SwiftUI .sheet, selecting "Use Photo" resulted in multiple unintended instances of the picker being initialized and presented. The console logs showed repeated "Camera initialized" and "Camera sheet appeared" messages (e.g., multiple <UIImagePickerController: 0x...> instances) after the initial dismissal, despite the sheet being dismissed programmatically. Reproduction Steps: Create a SwiftUI view with a button that sets a @State variable showCamera to true. Present a UIImagePickerController via .sheet(isPresented: $showCamera). Update a @Binding variable (e.g., photoLocation: URL?) in imagePickerController(_:didFinishPickingMediaWithInfo:) after saving the image. Dismiss the picker with picker.dismiss(animated: true) and presentationMode.wrappedValue.dismiss(). Observe that updating the @Binding variable triggers a view re-render, causing the .sheet to re-present multiple times before finally staying dismissed. Root Cause: A race condition occurred between the view update (triggered by changing photoLocation) and the dismissal of the picker. During the re-render, showCamera remained true momentarily, causing the .sheet modifier to re-evaluate and spawn new picker instances before the onDismiss closure could reset showCamera to false. The fix involved delaying the @Binding update (photoLocation) until after the picker and sheet were fully dismissed, ensuring showCamera was reset to false before the view re-rendered: Introduced an onPhotoPicked: (URL) -> Void closure to decouple the photoLocation update from the dismissal timing. Modified the coordinator to call onPhotoPicked and reset showCamera before initiating dismissal:swift Issue 2: Single Unintended Picker Reopen After Initial Fix Description: After addressing the multiple-instance issue, a single unintended reopen of the picker persisted. The logs showed one additional "Camera initialized" and "Camera sheet appeared" after "Use Photo," before the final dismissal. Reproduction Steps: Reproduction Steps: Use the initial fix with onPhotoPicked and delayed photoLocation update. Take a photo and select "Use Photo." Observe one extra picker instance appearing briefly before dismissal completes. Root Cause: The @Binding update (photoLocation) was still occurring too early in the dismissal sequence. Although delayed until after picker.dismiss, the view re-render happened while showCamera was still true during the dismissal animation, causing the .sheet to re-present once before onDismiss reset showCamera. Resolution: The fix ensured showCamera was set to false before the picker dismissal animation began, preventing the .sheet from re-evaluating during the transition: Moved the dismissCamera() call (which sets showCamera to false) into the onPhotoPicked callback, executed before picker.dismiss: CameraView( photoLocation: $photoLocation, storeDirectory: storeDirectory, onPhotoPicked: { url in print("Photo picked callback for \(id), setting photoLocation: \(url)") self.photoLocation = url self.cameraState.dismissCamera() // Sets showCamera to false first } ) Kept the dismissal sequence in the coordinator: DispatchQueue.main.async { self.parent.onPhotoPicked(fileURL) picker.dismiss(animated: true) { self.parent.presentationMode.wrappedValue.dismiss() } } This synchronized the state change with the dismissal, ensuring showCamera was false before the view re-rendered, eliminating the single reopen. Request: Could the SwiftUI team clarify if this behavior is expected, or consider improving the .sheet modifier to better handle state transitions during UIKit controller dismissal? A more robust bridge between SwiftUI’s declarative state and UIKit’s imperative lifecycle could prevent such race conditions.
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
90
Mar ’25
App Download Banner in App Clip downloads but does NOT open app
In our app clip, we open/show the full app download banner. We used to have the expected behavior, but with seemingly no changes to the app download banner code we have the following issue. Expected behavior: App download banner shows in app clip, user presses "Get" button, app is downloaded and installs, "Get" button changes to "Open" button (note: button is blue), user presses "Open" button and the full app is opened. Current behavior: App download banner shows in app clip, user presses "Get" button, app is downloaded and installs, "Get" button changes to "Open" button (note: button is now grey), user presses "Open" button but nothing happens. With the current behavior, the full app is correctly downloaded and the appclip removes itself from the phone, but the open button does nothing.
3
0
378
Feb ’25
How to override NSWindow in a pure SwiftUI Application
So I am looking to use a custom NSWindow application (so I can implement some enhanced resizing/dragging behavior which is only possible overriding NSWindow). The problem is my whole application is currently SwiftUI-based (see the project here: https://github.com/msdrigg/Roam/blob/50a2a641aa5f2fccb4382e14dbb410c1679d8b0c/Roam/RoamApp.swift). I know there is a way to make this work by dropping my @main SwiftUI app and replacing it with a SwiftUI root view hosted in a standard AppKit root app, but that feels like I'm going backwards. Is there another way to get access (and override) the root NSWindow for a SwiftUI app?
0
0
297
Mar ’25
Persistent 'buildExpression unavailable' error in ContentView with switch/AppState
Hi everyone, I'm encountering a persistent build error in a SwiftUI iOS app and I'm running out of ideas. Setup: My ContentView uses two @EnvironmentObjects (GameViewModel, SettingsStore). The GameViewModel has an AppState enum (.welcome, .setup, .game). The ContentView body uses a switch viewModel.currentAppState (wrapped in a Group) to display one of three different views (WelcomeView, SetupView, GameView). Navigation between states is triggered by changing viewModel.currentAppState within withAnimation blocks in the respective subviews. Problem: I consistently get the build error 'buildExpression' is unavailable: this expression does not conform to 'View' pointing to the lines inside the .setup and .game cases of the switch statement in ContentView. Code (ContentView.swift - Simplified Test Version that STILL fails): // Zweck: Steuert die Hauptnavigation basierend auf AppState // KORRIGIERTE VERSION OHNE .animation(...) am Ende import SwiftUI struct ContentView: View { // Zugriff auf das ViewModel, um den AppState zu lesen @EnvironmentObject var viewModel: GameViewModel // SettingsStore wird von untergeordneten Views benötigt @EnvironmentObject var settingsStore: SettingsStore var body: some View { // Optional: Group um das switch-Statement, kann manchmal helfen (kannst du auch weglassen) Group { // Wechsle die Ansicht basierend auf viewModel.currentAppState switch viewModel.currentAppState { case .welcome: WelcomeView() // EnvironmentObjects an WelcomeView übergeben .environmentObject(viewModel) .environmentObject(settingsStore) // Übergangsanimation .transition(.opacity) case .setup: SetupView() // EnvironmentObjects an SetupView übergeben .environmentObject(viewModel) .environmentObject(settingsStore) // Übergangsanimation .transition(.asymmetric(insertion: .move(edge: .trailing), removal: .move(edge: .leading))) case .game: GameView() // EnvironmentObjects an GameView übergeben .environmentObject(viewModel) .environmentObject(settingsStore) // Übergangsanimation .transition(.asymmetric(insertion: .move(edge: .trailing), removal: .move(edge: .leading))) } } // Ende der optionalen Group // !!! WICHTIG: KEIN .animation(...) Modifier hier !!! } } // Vorschau struct ContentView_Previews: PreviewProvider { static var previews: some View { // Erstelle Instanzen für die Vorschau let vmWelcome = GameViewModel() vmWelcome.currentAppState = .welcome let vmSetup = GameViewModel() vmSetup.currentAppState = .setup let vmGame = GameViewModel() vmGame.currentAppState = .game vmGame.currentCard = Card.defaultCards.first let settings = SettingsStore() // Zeige verschiedene Zustände in der Vorschau an Group { ContentView() .environmentObject(vmWelcome) .environmentObject(settings) .previewDisplayName("Welcome State") ContentView() .environmentObject(vmSetup) .environmentObject(settings) .previewDisplayName("Setup State") ContentView() .environmentObject(vmGame) .environmentObject(settings) .previewDisplayName("Game State") } } } Troubleshooting Steps Taken (No Success): Ensured correct placement of .environmentObject modifiers on subviews within the switch. Removed a previous .animation() modifier applied directly to the switch. Ensured state changes triggering transitions are wrapped in withAnimation. Wrapped the switch in a Group. Multiple "Clean Build Folder". Deleted entire Derived Data folder (with Xcode closed). Restarted Xcode and the Mac multiple times. Deleted and recreated ContentView.swift with the code above. Crucially: The errors persist even when replacing WelcomeView(), - - - --- SetupView(), and GameView() with simple Text("...") views inside the switch cases (as shown in the code snippet above). Environment: Xcode Version: newest macOS Version: newest Question: Does anyone have any idea why the compiler would still fail to type-check this switch structure, even when the views inside are simplified to basic Text? What else could I try to diagnose or fix this? Could it be related to the subviews (SetupView/GameView) potentially having their own NavigationView or complexity, even when replaced by Text in the failing ContentView? Thanks for any suggestions!
Topic: UI Frameworks SubTopic: SwiftUI
2
0
174
Apr ’25
How to correctly and simply remove the edges of listStyle sidebar?
Hello, I've managed to get rid of these spaces in different ways. Using scrollview, giving negative insets, rewriting modifiers from scratch with plain style etc. But I couldn't solve this with a simple solution. I've read comments from many people experiencing similar problems online. It seems like there isn't a simple modifier to remove these spaces when we use sidebar as the list style in SwiftUI, or I couldn't find the simple solution. I wonder what's the simplest and correct way to reset these spaces? let numbers = Array(1...5) @State private var selected: Int? var body: some View { List(numbers, id: \.self, selection: $selected) { number in HStack { Text("Test") Spacer() } .frame(maxWidth: .infinity, alignment: .leading) } .listStyle(.sidebar) } }
0
0
192
Mar ’25
Stage Manager - UIWindowScene sizeRestrictions on iPad
Hello everyone, The setup: I have an iPadOS app. The app does not require full screen (Requires full screen option is disabled). The problem: The app starts looking unpolished when the canvas becomes too small. What I tried: I am trying to limit the canvas size for our app when run in Stage Manager. How: I saw that UIWindowScene has sizeRestrictions. This property is not always set as per documentation: https://developer.apple.com/documentation/uikit/uiwindowscene/sizerestrictions From my experiments, it only works when it's run on MacOS (in compatibility mode in our case). Console logs: Stage Manager - Requires full screen - OFF willConnectToSession - sizeRestrictions: nil sceneDidBecomeActive - sizeRestrictions: nil Stage Manager - Requires full screen - ON willConnectToSession - sizeRestrictions: nil sceneDidBecomeActive - sizeRestrictions: nil Stage Manager - Requires full screen - OFF - RUN on MacOS willConnectToSession - sizeRestrictions: Available sceneDidBecomeActive - sizeRestrictions: Available Question: Is there a way to enforce this minimum canvas size?
Topic: UI Frameworks SubTopic: UIKit
0
0
86
Mar ’25
SwiftUI FileDocument: Modify the default save dialog
Is it possible to change the default save dialog that appears when creating a document based MacOS app in SwiftUI? I have a basic FileDocument struct that gets called to a view using a DocumentGroup scene. struct MyFile: FileDocument { static let readableContentTypes: [UTType] = [.myFileType] static let writeableContentTypes: [UTType] = [.myFileType] var list: [String] init(configuration: ReadConfiguration) throws { let data = configuration.file.regularFileContents! let JSONDecoder = JSONDecoder() do { try list = JSONDecoder.decode([String].self, from: data) } catch { throw CocoaError(.fileReadCorruptFile) } } func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper { let JSONEncoder = JSONEncoder() JSONEncoder.outputFormatting = .prettyPrinted do { data = try JSONEncoder.encode(self.list) } catch { print(error.localizedDescription) throw CocoaError(.fileWriteUnknown) } return .init(regularFileWithContents: data) } } This gets called at the DocumentGroup DocumentGroup(newDocument: MyFile(), editor: { document in ContentView(document: document.$document) }) But when I save the file, I want the save dialog that appears to have something like a 'Tags' textField that can also store information about the file. Something similar to this: (https://i.sstatic.net/AJQ3YNb8.png) From what I can find, there isn't much information about this other than manually creating an NSSavePanel class and overriding the current save function
1
0
475
Mar ’25
Issue with Parent selecting child's apps using Family Controls API
I'm trying to accomplish the features in this video where the child device requests permission from parent to control scren time. Then the parent can choose apps on the childs phone from their phone. Everything on the childs device is working exactly like in the video. However, on the parents phone, when the FamilyActivityPicker appears, it's only the apps on the parents phone and when an app is selected, nothing changes in the FamilyActivitySelection. I found this forum post describe the same issue I am having. I have a physical device logged in the child and a simulator running as the parent. Why can't I see the child's apps on the parents phone? Is it cause I'm running one of them on a simulator?
2
0
503
Mar ’25
How do you pass a view builder into a view?
I'm making a custom control, specifically a checkbox next to a "label." I want the label parameter, like many in Apple's built-in controls, to take a view-building closure. But I can't figure out the correct syntax. I looked at the declaration of Apple's NavigationLink control for clues: public struct NavigationLink<Label, Destination> : View where Label : View, Destination : View { /// Creates a navigation link that presents the destination view. /// - Parameters: /// - destination: A view for the navigation link to present. /// - label: A view builder to produce a label describing the `destination` /// to present. public init(@ViewBuilder destination: () -> Destination, @ViewBuilder label: () -> Label) But when I mimic this, the compiler complains about the body() function: struct CheckboxItem<Label> : View where Label : View { let stateCheck: () -> Bool let label: () -> any View let boxSize: CGFloat init(withStateCheck: @escaping () -> Bool, boxSize: CGFloat, @ViewBuilder label: @escaping () -> Label) { stateCheck = withStateCheck self.label = label self.boxSize = boxSize } var body: some View { HStack { <-- ERROR: "Type 'any View' cannot conform to 'View'" Image(systemName: stateCheck() ? "checkmark.square" : "square") .resizable() .aspectRatio(contentMode: .fit) .frame(width: boxSize, height: boxSize) .foregroundColor(AppStyle.labelColor) .opacity(0.75) label() } } } Also, note that I had to put @escaping before my label parameter, but that's not seen in Apple's. Any ideas?
Topic: UI Frameworks SubTopic: SwiftUI
1
0
212
Mar ’25