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

Detect user's tap on status bar
I have an app which uses Scene var body: some Scene { WindowGroup { RootView(root: appDelegate.root) .edgesIgnoringSafeArea(.all) .onOpenURL { url in let stringUrl = url.absoluteString if (stringUrl.starts(with: "http")) { handleUniversalLink(url: stringUrl) } else if (stringUrl.starts(with: "fb")) { let _ = ApplicationDelegate.shared.application( UIApplication.shared, open: url, sourceApplication: nil, annotation: [UIApplication.OpenURLOptionsKey.annotation]) } } } } I need to detect when a user taps on status bar. And call some functions when he does it. Is it possible in Swift?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
254
Feb ’25
Crash: KEY_TYPE_OF_DICTIONARY_VIOLATES_HASHABLE_REQUIREMENTS
Hi everyone, frome time to time I see crash which Im not able to debug, because there is no line of my code where crash occured. This is a crash log what Im getting from time to time of some users. In my device I never get this kind of crash. 0 libswiftCore.dylib 0x1172c _assertionFailure(_:_:flags:) + 208 1 libswiftCore.dylib 0x198624 KEY_TYPE_OF_DICTIONARY_VIOLATES_HASHABLE_REQUIREMENTS(_:) + 2980 2 libswiftCore.dylib 0xdb6c8 specialized _NativeDictionary.uncheckedRemove(at:isUnique:) + 534 3 libswiftCore.dylib 0xb250c Dictionary._Variant.setValue(_:forKey:) + 204 4 libswiftCore.dylib 0x5a620 Dictionary.subscript.setter + 520 5 SwiftUICore 0xf62ec ForEachState.item(at:offset:) + 4340 6 SwiftUICore 0xf5054 ForEachState.forEachItem(from:style:do:) + 1796 7 SwiftUICore 0x2272f8 ForEachState.traitKeys.getter + 84 8 SwiftUICore 0x227298 ForEachList.traitKeys.getter + 24 9 SwiftUICore 0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76 10 SwiftUICore 0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76 11 SwiftUICore 0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76 12 SwiftUICore 0x227008 protocol witness for ViewList.traitKeys.getter in conformance SubgraphList + 76 13 SwiftUICore 0x2271fc DynamicViewList.WrappedList.traitKeys.getter + 88 27 SwiftUICore 0x226d18 specialized static SectionAccumulator.processUnsectionedContent(list:contentSubgraph:) + 84 28 SwiftUI 0x26afe0 ListSectionInfo.init(list:listAttribute:contentSubgraph:) + 132 29 SwiftUI 0x269bb0 UpdateCollectionViewListCoordinator.updateValue() + 1528 30 SwiftUI 0x785d4 partial apply for implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>(_:) + 32 31 AttributeGraph 0xccac AG::Graph::UpdateStack::update() + 540 32 AttributeGraph 0xc870 AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 424 33 AttributeGraph 0xc444 AG::Subgraph::update(unsigned int) + 848 34 SwiftUICore 0x805a8 GraphHost.flushTransactions() + 860 35 SwiftUI 0x1ac84 closure #1 in _UIHostingView._renderForTest(interval:) + 24 36 SwiftUICore 0x7ffa8 partial apply for closure #1 in ViewGraphDelegate.updateGraph<A>(body:) + 28 37 SwiftUICore 0x7fd6c ViewRendererHost.updateViewGraph<A>(body:) + 120 38 SwiftUICore 0x7fce8 ViewGraphDelegate.updateGraph<A>(body:) + 84 39 SwiftUI 0x3e688 closure #1 in closure #1 in closure #1 in _UIHostingView.beginTransaction() + 172 40 SwiftUI 0x3e5d4 partial apply for closure #1 in closure #1 in closure #1 in _UIHostingView.beginTransaction() + 24 41 SwiftUICore 0x79720 closure #1 in static Update.ensure<A>(_:) + 56 42 SwiftUICore 0x796a4 static Update.ensure<A>(_:) + 100 43 SwiftUI 0x9c808 partial apply for closure #1 in closure #1 in _UIHostingView.beginTransaction() + 80 44 SwiftUICore 0x7f5e0 thunk for @callee_guaranteed () -> () + 28 45 SwiftUICore 0x6161c specialized closure #1 in static NSRunLoop.addObserver(_:) + 144 46 CoreFoundation 0x218a4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 36 47 CoreFoundation 0x213f8 __CFRunLoopDoObservers + 552 48 CoreFoundation 0x75da8 __CFRunLoopRun + 948 49 CoreFoundation 0xc8284 CFRunLoopRunSpecific + 588 50 GraphicsServices 0x14c0 GSEventRunModal + 164 51 UIKitCore 0x3ee674 -[UIApplication _run] + 816 52 UIKitCore 0x14e88 UIApplicationMain + 340 53 SwiftUI 0x291ef8 closure #1 in KitRendererCommon(_:) + 168 54 SwiftUI 0x291e28 runApp<A>(_:) + 100 55 SwiftUI 0x291d0c static App.main() + 180 56 DholRainbow 0x3019e8 main + 4339145192 (DholRainbowApp.swift:4339145192) 57 ??? 0x1b0bf5de8 (Missing) From Crashlytics I know at least human readable format of this error Fatal error: Duplicate keys of type 'Contact' were found in a Dictionary. This usually means either that the type violates Hashable's requirements, or that members of such a dictionary were mutated after insertion. I 've checked all my parts of code where Im using dictionary. This is a function which creating that particulary dictionary. private func logsByDate() { let groupedByDate = Dictionary(grouping: logs.filter { ($0.remoteParty as? Contact != nil) } ) { $0.date.removeTimeStamp ?? .distantPast }.mapValues { $0.compactMap { $0 } } var dayLogs = [DayLog]() for date in groupedByDate { var contacts = [CallLogContact]() for log in logs.filter({ $0.date.removeTimeStamp ?? .distantPast == date.key }) { if let contact = log.remoteParty as? Contact { if contacts.firstIndex(where: {$0.contact == contact }) == nil { let contactDayLogs = logs.filter({ $0.remoteParty as? Contact == contact && $0.date.removeTimeStamp == date.key}) contacts.append( CallLogContact( contact: contact, logs: contactDayLogs, lastCallLogDate: contactDayLogs.sorted(by: {$0.date > $1.date}).first?.date ?? .distantPast ) ) } } } dayLogs.append(DayLog(date: date.key, contact: contacts)) } DispatchQueue.main.async { self.groupedCallLogs = dayLogs } } This function is called from 3 others functions based on notification from the server in case of new call log, fetched call logs and removed call logs.
0
0
284
Mar ’25
detecting modifier keys using UITextFieldDelegate protocol
I have a UITextField in my application, and I want to detect all the keys uniquely to perform all relevant task. However, there is some problem in cleanly identifying some of the keys. I m not able to identify the backspace key press in the textField(_:shouldChangeCharactersIn:replacementString:) method. Also I don't know how to detect the Caps Lock key. I am intending to so this because I want to perform some custom handling for some keys. Can someone help me with what is the way of detecting it under the recommendation from apple. Thanks in advance. Note: checking for replacementString parameter in shouldChangeCharactersIn method for empty does not help for backspace detection as it overlaps with other cases.
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
150
Mar ’25
UI not updating during render
I've coded a small raytracer that renders a scene (based on Peter Shirley's tutorial, I just coded it in Swift). The raytracer itself works fine, outputs a PPM file which is correct. However, I was hoping to enclose this in a UI that will update the picture as each pixel value gets updated during the render. So to that end I made a MacOS app, with a basic model-view architecture. Here is my model: // // RGBViewModel.swift // rtweekend_gui // // import SwiftUI // RGB structure to hold color values struct RGB { var r: UInt8 var g: UInt8 var b: UInt8 } // ViewModel to handle the RGB array and updates class RGBViewModel: ObservableObject { // Define the dimensions of your 2D array let width = 1200 let height = 675 // Published property to trigger UI updates @Published var rgbArray: [[RGB]] init() { // Initialize with black pixels rgbArray = Array(repeating: Array(repeating: RGB(r: 0, g: 0, b: 0), count: width), count: height) } func render_scene() { for j in 0..&lt;height { for i in 0..&lt;width { // Generate a random color let r = UInt8.random(in: 0...255) let g = UInt8.random(in: 0...255) let b = UInt8.random(in: 0...255) // Update on the main thread since this affects the UI DispatchQueue.main.async { // Update the array self.rgbArray[j][i] = RGB(r: r, g: g, b: b) } } } } and here is my view: // // RGBArrayView.swift // rtweekend_gui // // import SwiftUI struct RGBArrayView: View { // The 2D array of RGB values @StateObject private var viewModel = RGBViewModel() // Control the size of each pixel private let pixelSize: CGFloat = 1 var body: some View { VStack { // Display the RGB array Canvas { context, size in for y in 0..&lt;viewModel.rgbArray.count { for x in 0..&lt;viewModel.rgbArray[y].count { let rgb = viewModel.rgbArray[y][x] let rect = CGRect( x: CGFloat(x) * pixelSize, y: CGFloat(y) * pixelSize, width: pixelSize, height: pixelSize ) context.fill( Path(rect), with: .color(Color( red: Double(rgb.r) / 255.0, green: Double(rgb.g) / 255.0, blue: Double(rgb.b) / 255.0 )) ) } } } .border(Color.gray) // Button to start filling the array Button("Render") { viewModel.render_scene() } .padding() } .padding() .frame(width: CGFloat(viewModel.width) * pixelSize + 40, height: CGFloat(viewModel.height) * pixelSize + 80) } } // Preview for SwiftUI struct RGBArrayView_Previews: PreviewProvider { static var previews: some View { RGBArrayView() } } The render does work and the image displays, however, I thought I set it up to show the image updating pixel by pixel and that doesn't happen, the image shows up all at once. What am I doing wrong?
0
0
96
May ’25
macos 15, savepanel return the wrong path when saving files occasionally
macOS: 15.0 macFUSE: 4.8.3 I am using rclone + macFUSE and mount my netdisk where it has created three subdirectories in its root directory: /user, /share, and /group. When I save a file to /[root]/user using NSSavePanel and name it test.txt, I expect the file to be saved as: /[root]/user/test.txt However, occasionally, the delegate method: - (BOOL)panel:(id)sender validateURL:(NSURL *)url error:(NSError **)outError { } returns an incorrect path: /[root]/test.txt This issue only occurs when selecting /user. The same operation works correctly for /share and /group. Is there any logs I could provide to help solving this issue? Many thanks!
Topic: UI Frameworks SubTopic: AppKit Tags:
0
0
390
Feb ’25
Unexpected UINavigationBar Behavior During View Transitions in iOS 18
In iOS 18, I've observed unexpected behavior related to the UINavigationBar when transitioning between view controllers that have differing navigation bar visibility settings. Specifically, when returning from a modal presentation or a web view, the navigation bar reappears with an unexpected height (e.g., 103 points) and lacks content, displaying only an empty bar. Start with a UIViewController (e.g., HomeViewController) where the navigation bar is hidden using: override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) navigationController?.setNavigationBarHidden(true, animated: animated) } Present another UIViewController (e.g., a web view) modally. Dismiss the presented view controller. Observe that upon returning to HomeViewController, the navigation bar is visible with increased height and lacks expected content. Expected Behavior: The navigation bar should remain hidden upon returning to HomeViewController, maintaining the state it had prior to presenting the modal view controller. Actual Behavior: Upon dismissing the modal view controller, the navigation bar becomes visible with an unexpected height and lacks content, leading to a disrupted user interface. Additional Observations: This issue is specific to iOS 18; it does not occur in iOS 17 or earlier versions. The problem seems to stem from setting the navigation bar to be visible in the viewWillDisappear method, as shown below: override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) navigationController?.setNavigationBarHidden(false, animated: animated) } Removing or modifying this line mitigates the issue, suggesting a change in the view controller lifecycle behavior in iOS 18. Request for Clarification: Is this change in behavior intentional in iOS 18, or is it a regression? Understanding whether this is a new standard or a bug will help in implementing appropriate solutions. Workaround: As a temporary measure, I've adjusted the navigation bar visibility settings to avoid changing its state in viewWillDisappear, instead managing it in viewWillAppear or viewDidAppear. References: Similar issues have been discussed in the Apple Developer Forums: iPad OS 18 UINavigationBar display incorrectly
Topic: UI Frameworks SubTopic: UIKit
0
0
109
May ’25
Use Custom UIApplication Subclass with SwiftUI
I have a SwiftUI app which needs the Ivanti AppConnect SDK. The docs only show how to integrate it into a Swift/UIKit app. But I need it to work with SwiftUI. I probably could make a UIKit base app and then load my existing SwiftUI views and code through a SwiftUI component host or something. But I'd like to avoid that if possible. Here is where I'm stuck: The AppConnect framework loads through a custom UIApplication subclass in the main.swift file: import Foundation import AppConnect UIApplicationMain( CommandLine.argc, CommandLine.unsafeArgv, ACUIApplicationClassName, NSStringFromClass(AppDelegate.self) ) The startup works as expected, and the expected function is called in the AppDelegate class: func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {...} However, the SwiftUI view is not loaded and the scree stays blank. I implemented a SceneDelegate.swift class which doesn't seem to be called. Also, the following function in the AppDelegate doesn't get called either: func application( _ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {...} So how do I bootstrap SwiftUI with a custom UIApplication class? can that be done with the @main macro somehow? I'm still pretty new to Swift and iOS development. Any help is appreciated
Topic: UI Frameworks SubTopic: SwiftUI Tags:
0
0
68
May ’25
Display a broader track of a user on ios app with Mapkit.
Hello I'm currently building a feature within an ios app using SwiftUI and Mapkit to record the gps cordinates of a user as they move and render the track on the map. the idea is not really to have a "track" but to have a visual representation of the area the user sees while they are moving around. I need this width/breadth to be relative to the map and not the screen, such that when I zoom in and out of the map, the size will adjust automatically.
0
0
70
May ’25
Why is the pitch slider visible in SwiftUI tvOS map view?
Why is the pitch slider always visible in the SwiftUI tvOS map view? It doesn't even appear to be supported there, let alone the fact that I specify mapControlVisibility(.hidden). Am I missing something or is Apple? See attached screenshot. This really messes up my UI. Here is my code: import SwiftUI import MapKit struct ContentView: View { @State var position = MapCameraPosition.region(MKCoordinateRegion( center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194), span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05))) var body: some View { Map(position: $position) .mapControlVisibility(.hidden) .mapStyle(.standard(pointsOfInterest: .including(.airport))) } }
0
0
278
Mar ’25
progress view does not work
I have an app that run Monte Carlo simulations. I run thousands of simulations in the app and a simulation runs can take on the order of 30 seconds to a minute to complete. I would like to have a progress view that tracks the number of simulation runs. How can I implement this in swiftui?
0
0
173
Mar ’25
Detect change to apps Screen Time Access
I'm creating an app which gamifies Screen Time reduction. I'm running into an issue with apples Screen Time setting where the user can disable my apps "Screen Time access" and get around losing the game. Is there a way to detect when this setting is disabled for my app? I've tried using AuthorizationCenter.shared.authorizationStatus but this didn't do the trick. Does anyone have an ideas?
0
0
426
Feb ’25
In navigationLink closure, FocusState doesn't work in sheet
Hello, I have a question about FocusState, navigationLink and sheet, the code which in navigationLink closure doesn’t work, but work without navigationLink, just like the following code struct ContentView: View { var body: some View { NavigationStack { // this work interView() // this doesn't work NavigationLink { interView() } label: { Text("into interView") } } } } struct interView: View { @FocusState var focusStateA : Int? @State var show : Bool = false @State var text: String = "" var body: some View { ScrollView { VStack { coreView Button("Detail") { show.toggle() } } .sheet(isPresented: $show, content: { coreView }) } } } extension interView { var coreView : some View { VStack { VStack { putdown TextField("hi", text: $text) .focused($focusStateA , equals: 1) } } } var putdown : some View { Button(action: { if focusStateA != nil { focusStateA = nil print("OK") } else { print("It's nil") } }, label: { Text("Put down the keyboard") }) } } and there are some strange phenomena, I must put all view into a scrollview, otherwise, it even doesn’t work without navigationLink This problem has existed in IOS 18, and now in IOS26 still doesn’t be settled, is it a problem or some character?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
56
Jun ’25
Open file directly into editor view with DocumentGroup
This was also raised in FB17028569 I have iOS document based app using DocumentGroup. I can create and save documents as expected. All that functionality is fine. @main struct FooBarApp: App { var body: some Scene { DocumentGroup(newDocument: { FoobarDocument() }) { config in MainView(document: config.document) } The problem is when I open an app document from Files.app or Messages the document is never opened directly into the editor, the document browser interface is always presented and the user must manually select the document to open an editor. This also happens when I use UIApplication.shared.requestSceneSessionActivation(nil, userActivity: activity, options: nil) to open a new scene. The doc isn't opened into my editor. I believe my plist document types are setup correctly and that my ReferenceFileDocument is setup correctly <key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key> <array> <string>foobar</string> </array> <key>CFBundleTypeIconFile</key> <string>icon-128</string> <key>CFBundleTypeIconSystemGenerated</key> <integer>1</integer> <key>CFBundleTypeMIMETypes</key> <array> <string>application/json</string> </array> <key>CFBundleTypeName</key> <string>Foobar Project</string> <key>LSHandlerRank</key> <string>Owner</string> <key>LSItemContentTypes</key> <array> <string>com.digital-dirtbag.foobar</string> </array> <key>NSUbiquitousDocumentUserActivityType</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER).ubiquitousdoc</string> </dict> </array> <key>UTExportedTypeDeclarations</key> <array> <dict> <key>UTTypeConformsTo</key> <array> <string>public.data</string> </array> <key>UTTypeDescription</key> <string>Foobar Project</string> <key>UTTypeIconFiles</key> <array> <string>icon-128.png</string> </array> <key>UTTypeIdentifier</key> <string>com.digital-dirtbag.foobar</string> <key>UTTypeTagSpecification</key> <dict> <key>public.filename-extension</key> <array> <string>foobar</string> </array> </dict> </dict> The question is does DocumentGroup on iOS even support opening documents directly into the editor view? I know it works on macOS as expected as I tried this with the demo code and it exhibits the same symptoms. Opening a document from iOS Files.app only gets you as far as the document browser while macOS will open an editor directly.
Topic: UI Frameworks SubTopic: SwiftUI
0
0
71
May ’25
Bundling OSX installer plugin with productbuild/pkgbuild
I'm trying to create a .pkg installer with productbuild/pkgbuild. But I'd also like to add my custom installer plugin to this. I'm using the following script. I'd like to add my bundle into this script. Since there are no official docs from apple how to do this nor there are a lot of updated resources, here are some things I have tried. adding the following line to Distrubtion.xml <bundle id="pluginid" path="path/to/myplugin.bundle"/> adding component tag to pkgbuild also doesn't do anything --component "path/to/myplugin.bundle" The bundle itself is build with XCode - it is a simple UI for user to type some input in Apple provides documentation for Distribution.xml file, which supports different UI elements but doesn't support text input - docs I have been also looking at this tutorial , it is very outdated but i could still fit it to my needs except the part where the .bundle file needs to be inserted into .pkg. Note - there is no option to view the contents of .pkg file build with pkbuild/productbuild How can i do this process correctly? I would like to link my installer pane plugin to a generic .pkg(with licenses and so on). I'd appreciate any kind of help!
0
0
108
May ’25
tvOS Remote Control Entitlements
I've been looking for a solution to configure the Apple TV remote(s) from the 5th generation and upwards. Some of the basic functionalities are disabling buttons on the physical remote control while maintaining proper functionality on remote controller apps on iOS devices. There seems to be a lack of relevant entitlements in that category, and without it I can't seem to figure out a way to make it work. Any ideas on the matter? Maybe a workaround that allows to configure the Apple TV to work with other remotes? Thank you in advance to anyone that put in thought to my query.
0
0
101
May ’25
Task cancellation behaviour
Hi everyone, I believe this should be a simple and expected default behavior in a real-world app, but I’m unable to make it work: 1. I have a View (a screen/page in this case) that calls an endpoint using async/await. 2. If the endpoint hasn’t finished, but I navigate forward to a DetailView, I want the endpoint to continue fetching data (i.e., inside the @StateObject ViewModel that the View owns). This way, when I go back, the View will have refreshed with the fetched data once it completes. 3. If the endpoint hasn’t finished and I navigate back to the previous screen, I want it to be canceled, and the @StateObject ViewModel should be deinitialized. I can achieve 1 and 3 using the .task modifier, since it automatically cancels the asynchronous task when the view disappears: view .task { await vm.getData() } I can achieve 1 and 2 using a structured Task in the View (or in the ViewModel, its the same behavior), for example: .onFirstAppearOnly { Task { away vm.getData() } } onFirstAppearOnly is a custom modifier that I have for calling onAppear only once in view lifecycle. Just to clarify, dont think that part is important for the purpose of the example But the question is: How can I achieve all three behaviors? Is this really such an unusual requirement? My minimum deployment target is iOS 15, and I’m using NavigationView + NavigationLink. However, I have also tried using NavigationStack + NavigationPath and still couldn’t get it to work. Any help would be much appreciated. Thank you, folks!
0
0
419
Feb ’25
CPTabBarTemplate in CarPlay Simulator: Tab Becomes Inactive on Re-selection
I am facing an issue in my CarPlay app using CPTabBarTemplate. The app has two tabs, and on launch, the first tab is correctly selected. However, when I tap on the first tab again, instead of staying active, it becomes inactive. This behavior is unexpected, as re-selecting the active tab should typically maintain its selected state. Has anyone else encountered this issue or found a workaround to prevent the tab from becoming inactive?
0
0
58
May ’25