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

dismissWindow alternative for macOS 13?
Currently for my SwiftUI application i'm using dismissWindow() to close my windows. However, I want to make my app compatible on macOS 13 to enable a wider audience. My current usage of this function is as follows: func reloadContentViewAfterDelete() { @Environment(\.openWindow) var openWindow @Environment(\.dismissWindow) var dismissWindow dismissWindow(id: "content") openWindow(id: "content") }
1
0
359
Sep ’24
strange ios crash
HI i have found libsystem_kernel.dylib crash. i can't reproduce this error even this is not unrecognisable. here is stack trace Crashed: com.apple.main-thread 0 libsystem_kernel.dylib 0xaac mach_msg_trap + 8 1 libsystem_kernel.dylib 0x107c mach_msg + 72 2 CoreFoundation 0x6c88 + 368 3 CoreFoundation 0xaf90 + 1160 4 CoreFoundation 0x1e174 CFRunLoopRunSpecific + 572 5 GraphicsServices 0x1988 GSEventRunModal + 160 6 UIKitCore 0x4e5a88 + 1080 7 UIKitCore 0x27ef78 UIApplicationMain + 336 8 libTweaks.dylib 0x2a6b4 _apdecr_UIApplicationMain(int, char**, NSString*, NSString*) + 108 9 libswiftUIKit.dylib 0x27ee4 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 100 10 REDDI 0x214d6c main + 4368469356 (AppDelegate.swift:4368469356) 11 ??? 0x1028a84d0 (Missing)
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
383
Sep ’24
SwiftUI: listSectionSeparator not working on macOS
Hi, When I use 'listSectionSeparator' on hide the section separator on a List 'section', it works as expected on iOS, but doesn't have any effect on macOS. Is that a known issue? Are there any workarounds for this? Here's a basic reproducible example: import SwiftUI struct TestItem: Identifiable, Hashable { let id = UUID() let itemValue: Int var itemString: String { get { return "test \(itemValue)" } } } struct TestListSelection: View { let testArray = [TestItem(itemValue: 1), TestItem(itemValue: 2), TestItem(itemValue: 3), TestItem(itemValue: 4)] @State private var selectedItem: TestItem? = nil var body: some View { List (selection: $selectedItem) { Section("Header") { ForEach (testArray, id: \.self) { item in Button { print("main row tapped for \(item.itemValue)") } label: { HStack { Text(item.itemString) Spacer() Button("Tap me") { print("button tapped") } .buttonStyle(.borderless) } } .buttonStyle(.plain) } } .listSectionSeparator(.hidden) // has no effect on macOS Section("2nd Header") { ForEach (testArray, id: \.self) { item in Text(item.itemString) } } .listSectionSeparator(.hidden) // has no effect on macOS } .listStyle(.plain) } } #Preview { TestListSelection() }
1
1
532
Sep ’24
Widgets not displaying data when running on iOS 18
When I build my app on Xcode 16 and run it in an iOS 18 simulator The data downloaded in the app will not get to the widget. Same behaviour happens when running on a physical device. If I run the app in a iOS 17.5 simulator the widget gets and displays the data correctly. is there a setting that I need to change that I’ve missed? The app works perfectly on iOS 18 with a build built in Xcode 15.4
6
1
980
Sep ’24
UIDocumentBrowserViewController create new document used to work, but...
is now broken. (but definitely worked when I originally wrote my Document-based app) It's been a few years. DocumentBrowserViewController's delegate implements the following func. func documentBrowser(_ controller: UIDocumentBrowserViewController, didRequestDocumentCreationWithHandler importHandler: @escaping (URL?, UIDocumentBrowserViewController.ImportMode) -> Void) { let newDocumentURL: URL? = Bundle.main.url(forResource: "blankFile", withExtension: "trtl2") // Make sure the importHandler is always called, even if the user cancels the creation request. if newDocumentURL != nil { importHandler(newDocumentURL, .copy) } else { importHandler(nil, .none) } } When I tap the + in the DocumentBrowserView, the above delegate func is called (my breakpoint gets hit and I can step through the code) newDocumentURL is getting defined successfully and importHandler(newDocumentURL, .copy) gets called, but returns the following error: Optional(Error Domain=com.apple.DocumentManager Code=2 "No location available to save “blankFile.trtl2”." UserInfo={NSLocalizedDescription=No location available to save “blankFile.trtl2”., NSLocalizedRecoverySuggestion=Enable at least one location to be able to save documents.}) This feels like something new I need to set up in the plist, but so far haven't been able to discover what it is. perhaps I need to update something in info.plist? perhaps one of: CFBundleDocumentTypes UTExportedTypeDeclarations Any guidance appreciated. thanks :-)
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
490
Sep ’24
How to close the keyboard using SwiftUI
I've been having trouble with finding a good way to allow the user to close the keyboard. Naturally, I'd like to use the keyboard toolbar but it's so inconsistent, it's impossible. Sometimes it shows up, other times it doesn't. At the moment, it's not appearing at all no matter where I put it. On the NavigationStack, on the List inside of it, on the TextField. It just doesn't appear. I added a TapGesture to my view to set my FocusState that I'm using for the fields back to nil, however, this stops the Picker I have from working. I tried using SimultaneousGesture with TapGesture, and that didn't work. For example: .simultaneousGesture( TapGesture() .onEnded() { if field != nil { field = nil } } ) With the current setup, each TextField switches to the next TextField in the onSubmit. The last one doesn't, which will close the keyboard, but I want to give people the option to close the keyboard before that. Does anyone have a good way to close the keyboard?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
326
Sep ’24
New `.animation(_:body:)` overload confusion
Hi folks, I’ve been trying to use the new .animation(_:body:) overload without success. I’m attempting to animate multiple properties of a view, each with different animations. This overload seems to be the perfect candidate to achieve that. Here's the code I'm using: struct ContentView: View { @State private var isAnimating = false var body: some View { Text("Hello World") .font(.largeTitle) .animation(.easeOut(duration: 1)) { $0.foregroundStyle(isAnimating ? .red : .blue) } .animation(.linear(duration: 10)) { $0.offset(x: isAnimating ? -100 : 0) } .onAppear { isAnimating = true } } } Pretty straightforward, but I don’t get any animations at all. Of course, I could wrap isAnimating = true in a withAnimation closure, but the WWDC session about those APIs mentions this is not needed. Furthermore, if I do that, the animations I provide in .animation(_:body:) are not being used. I’m really confused by this new API, and I’m starting to think it doesn’t work as advertised.
0
2
350
Sep ’24
10162: The SwiftUI cookbook for focus - does not work as expected with iOS 18
I try to create a sheet that shows a textfield and the textfield should gain the focus immediately after the sheet is presented. This use case is explained in Session 10162 at 11:21 and at 13:31 my desired behavior is shown. I could not get this to work in my own code and downloaded the sample code from here: https://developer.apple.com/documentation/swiftui/focus-cookbook-sample Then I opened the sample code and run it in the simulator. It does not focus when the sheet appears in a iOS 18 simulator using Xcode 16 installed via the AppStore. It does gain focus if I use the "add" Button. No changes made on the sample code. Just adjusted the Team setting to get a clean build. The behavior I get locally under iOS 18 is not what is shown in the session and I can't understand why. I tried the following Simulators (and platforms) iPhone 16, iPad Pro (M4, 11inch) and my Mac. On none of those the last item got focus just by presenting the sheet. Is it not possible to test this in a simulator? Could I have a configuration error? Given all the information I found yet, this seems like a Bug. It would be very helpful if someone could replicate my problem. Thank you for your help. Programm Versions: Xcode: Version 16.0 (16A242d) MacOS: 15.0 (24A335)
0
0
513
Sep ’24
Define the correct UIDocument subclass with the key UIDocumentClass
Hi there, I'm trying to migrate my app to using the UIDocumentViewController so I can use the new launch experience. My app exports a custom file type and uses UIDocument + UIDocumentBrowserViewController. I tried creating a UIDocumentViewController and making it the root view of my app but it doesn't recognise my custom document type. class Document_VC: UIDocumentViewController { var storyCardsDocument: PlotCardDocument? { self.document as? PlotCardDocument } override func viewDidLoad() { super.viewDidLoad() configureViewForCurrentDocument() } override func documentDidOpen() { configureViewForCurrentDocument() } func configureViewForCurrentDocument() { guard let document = storyCardsDocument, !document.documentState.contains(.closed) && isViewLoaded else { return } print("Document opened: \(document.fileURL)") } } The app opens but when I navigate to a document made in a previous version of the app it is greyed out. I also don't see a 'New' button in the launcher view. To try and see what I was doing wrong, I tested the markdown app sample code. When I make the UIDocumentViewController the root and try to open or create a new markdown document I get the following error: no document class found. Define the correct UIDocument subclass with the key UIDocumentClass in the info.plist's CFBundleDocumentTypes dictionary.
1
0
441
Sep ’24
Critical Rendering Bug in PencilKit on iPad with "More Space" Display Mode & Apple Pencil Hover Interaction
There is a significant rendering issue in PencilKit when using an iPad set to "More Space" display mode, combined with an Apple Pencil that supports hover functionality (e.g., Apple Pencil 2). This problem affects all applications that use PencilKit, including Apple's own Notes and Quick Note. The issue results in flickering black borders and subtle jittering while drawing, which is especially noticeable during tasks requiring precise handwriting, such as writing mathematical expressions. Due to the short strokes and frequent lifts and drops of the pencil, the jitter is much more pronounced, leading to visual discomfort and even dizziness after extended use. Steps to Reproduce: Open Settings on your iPad. Navigate to Display & Brightness > Display Zoom > More Space. Switch to the More Space display mode. Open the Notes app or trigger Quick Note from any application by swiping from the bottom-right corner. Start drawing or writing using the Apple Pencil (with hover functionality) in the writing area. Observe the display anomalies as you hover and write: Flickering black borders appear intermittently around the writing area. The strokes show subtle jittering whenever you lift and lower the pencil. This is particularly disruptive when writing short, precise strokes, such as those in mathematical expressions, where the frequent up-and-down motion makes the jitter more apparent. Expected Results: Smooth and stable drawing experience with no visual artifacts or jittering during interactions with the Apple Pencil, regardless of the display zoom settings. Actual Results: Flickering black borders intermittently appear during drawing. Jittering of strokes is noticeable, particularly when lifting and lowering the Apple Pencil for short strokes. This disrupts precise writing tasks, especially in cases like mathematical notation, where frequent pen lifts and short strokes make the jitter much more apparent. This can lead to discomfort (e.g., dizziness) after extended use. System-Wide Impact: This issue affects all apps that utilize PencilKit, including third-party apps such as Doodle Draw (link). Since PencilKit is a core framework, the rendering bug significantly degrades the user experience across multiple productivity and note-taking applications. Similar Reports: There are numerous discussions about this issue online, indicating that many users are experiencing the same problem. Reddit Discussion: https://www.reddit.com/r/ipad/comments/1f042ol/comment/ljvilv6/ Apple Support Thread Additionally, a feedback report (ID: FB15166022) related to this issue with Notes has been previously filed, but the bug remains unresolved. This bug severely impacts the usability of PencilKit-enabled apps, especially during tasks that involve frequent, precise pencil strokes, such as writing mathematical expressions. We kindly request the development team investigate this issue promptly to ensure a smooth, stable experience with the iPad's "More Space" display mode and Apple Pencil hover interaction.
1
0
623
Sep ’24
NavigationSplitView(sidebar:content:detail:) does not show View in content closure
View using NavigationSplitView(sidebar:content:detail:) in SwiftUI on tvOS does not show the View in the content closure and does not allow proper navigation. This occurs when NavigationSplitViewStyle is .automatic or .prominentDetail. It also occurs when not specified. You can avoid using this sidebar style by adding .navigationSplitViewStyle(.balanced). However, I would like to build an app employing this View. I would be glad to know what you have noticed and if you have any advice. Code Here is the code to reproduce it Just replace it with this and somehow the phenomenon occurs. import SwiftUI struct ContentView: View { @State var selected:Int? @State var selected2:Int? var body: some View { NavigationSplitView { List(selection: $selected){ NavigationLink(value: 1){ Label("1", systemImage: "1.circle") } NavigationLink(value: 2){ Label("2", systemImage: "2.circle") } NavigationLink(value: 3){ Label("3", systemImage: "3.circle") } } .navigationTitle("Sidebar") } content: { if let selected = selected { List(selection: $selected2){ NavigationLink(value: 1){ Label("1", systemImage: "1.square") } NavigationLink(value: 2){ Label("2", systemImage: "2.square") } NavigationLink(value: 3){ Label("3", systemImage: "3.square") } } .navigationTitle("Content \(selected)") } else { Text("No Selected") } } detail: { Group { if let selected2 = selected2 { Text(String(selected2)) }else{ Text("No Selected") } } .navigationTitle("Detail") .frame(maxWidth: .infinity, maxHeight: .infinity) } .navigationSplitViewStyle(.prominentDetail) } } Environment tvOS 18 Simulator (22J356) macOS 15.1 beta (24B5055e) Xcode 16.0 (16A242d) How to Reproduce Open the attached project with Xcode. Build the project on Apple TV with Xcode. press any button on the sidebar Confirm that the View in the content closure is not displayed. Actual Behavior The View in the content closure is not displayed, and the View in the detail closure is displayed. (4/4) Correct Behavior The View in the content closure is displayed, and when the button of the View is pressed, the View in the detail closure is displayed.
Topic: UI Frameworks SubTopic: SwiftUI
0
1
402
Sep ’24
Hiding Home Bar / Swipe up bar -- how to?
I'm working on an app that will be used in laboratory conditions. The application must be as dim as possible. For all the text and buttons, I'm thus using Color(red: 0.1, green: 0.0, blue: 0.0). However, a bright Home Bar / Swipe up bar emerges whenever the user interacts with the screen. This characteristic renders the iPhone useless in those conditions. In the Android version, such problems do not exist. And, I have yet to find a solution here in this forum or elsewhere. I must force the Home Bar to be invisible or Color(red: 0.1, green: 0.0, blue: 0.0). How to do that? Can anybody help?
Topic: UI Frameworks SubTopic: SwiftUI
0
1
281
Sep ’24
Registering variable fonts programatically
Is there an API to register .ttf files that have variables fonts (ie one or more axes specified). CTFontManagerRegisterGraphicsFont() makes only the default variation available. The same file when specified in UIAppFonts of Info.plist makes all the variants available (confirmed by querying UIFont.fontName(forFamilyName:)) This is mostly required for registering fonts that are bundled as part of a Swift package.
1
2
686
Sep ’24
Overzealous TextField Behavior
macOS 14.6.1, SwiftUI, Xcode 16.0 (developing for macOS) I have a TextField with a custom formatter and a custom binding (one created using Binding(get:set:). My understanding is that the TextField should only call on the formatter and update the binding when I commit the TextField by moving focus away from it, hitting return, etc. Unfortunately, that is not the case. I was able to verify that the formatter is being called (via NSLog added to the formatter code) every time I add a character to the field. Not only is this a waste of CPU resources, but in combination with the custom binding, it is causing a data entry issue for my application. I am writing a simple emulator for a computer system I concocted, and the formatter is formatting a memory location into its assembly language - the formatter's string method disassembles the instruction from the underlying memory value and the getObjectValue method assembles an input string back into the memory location. One example of an instruction would be the "set" instruction. All of these are valid forms for input to the assembler: set set 0 set x The "set" by itself is equivalent to "set 0", so what is happening is that I type "set" and the TextField immediately gets a valid response back from the formatter and updates the binding with the value of the "set 0" instruction. The custom binding updates the value in memory, which triggers the "get" method of the binding and updates the TextField with the disassembled value which helpfully adds the "0" to the field, setting it to "set 0" before I have a chance to type the "x". I need to manually delete the "0" from the line which I never typed there in the first place in order to finish typing the line of input. I either need a way to cause the TextField to behave the way it is supposed to and only update the binding when the value is committed, or a way to prevent the binding's get method from being retriggered by its own set method. Any ideas how to go about fixing this? Note that I set up a temporary TextField which was bound using a simple $binding to a state variable, and while the variable is updated whenever valid input is presented, it does not trigger the TextField to reread and thus I do not have the same input issue with that TextField. There is a reason why I need to use the custom get/set in context, however, so this is still an issue for me.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
229
Sep ’24
UICollectionView unwanted content offset change on invalidating layout
I have issue with unwanted changing offset in collection view to top or to near top. It is happening in collection view with vertical scroll when estimatedItemSize is not set to zero (main factor). If estimatedItemSize is zero it is always fine. It is SDK that provides items that should be loaded in few cells, items have dynamic height which is received from server and can be updated several times. Scenario when it happens (when was noticed) is 2 sections, in section 0 item is at index 4 of 14, section 1 is with only one cell with dynamic height item. If specific item is at index 0 in section 0 or have 1 cell per section (tried 15 sections and set items in sections 5 and 15) all is good regardless of estimatedItemSize. When new height is received if I call invalidateLayout or reloadItemAtIndexPaths it will “jump”. That same height is set in sizeForItemAtIndexPath. In some combinations it happens and in some not and that is the most annoying part. I tried setting estimated height to received height and it didn’t help (other cell may be smaller or larger). Also if I put items in one section at indexes 4 and 14 it “jumps”. I managed to make it work by setting at specific moment estimatedItemSize to zero then put back to one that SDK user set and didn’t see any issues but I was wondering if there is any other solution for this and did anyone had issue like this. It would be nice to have solution to keep one estimatedItemSize if it is not the default one (zero).
Topic: UI Frameworks SubTopic: UIKit
0
0
248
Sep ’24
Is there a way to know what size of icons is enabled in the home page?
Hey, i have an app that uses some calculations to replicate a transparent background in widgets, however given that in ios 18 we can now change the icons size to large, I wonder if there is a way to know what the user has currently selected and react to it? The workaround I have is that user needs to select a new config to switch the widget to large so re-calculations are done, but it would be nice if we there was a way for us to catch the new size.
0
0
299
Sep ’24
SwiftData Multiple ModelConfigurations
A ModelContainer with two configurations for two seperate models with one set to isStoredInMemoryOnly:false and the other one isStoredInMemoryOnly:true crashes after insertion. Anyone git this to work? import SwiftData @main struct RecipeBookApp: App { var container: ModelContainer init() { do { let config1 = ModelConfiguration(for: Recipe.self) let config2 = ModelConfiguration(for: Comment.self, isStoredInMemoryOnly: true) container = try ModelContainer(for: Recipe.self, Comment.self, configurations: config1, config2) } catch { fatalError("Failed to configure SwiftData container.") } } var body: some Scene { WindowGroup { ContentView() .modelContainer(container) } } } struct ContentView: View { @Environment(\.modelContext) private var context @Query private var recipes: [Recipe] @Query private var comments: [Comment] var body: some View { VStack { Button("Insert") { context.insert(Recipe(name:"Test")) context.insert(Comment(name:"Test")) } List(recipes){ recipe in Text(recipe.name) } List(comments){ comment in Text(comment.name) } } .padding() .onAppear(){ context.insert(Recipe(name:"Test")) context.insert(Comment(name:"Test")) } } } @Model class Recipe { internal init(name:String ) { self.name = name } var id: UUID = UUID() var name: String = "" } @Model class Comment { internal init(name:String ) { self.name = name } var id: UUID = UUID() var name: String = "" }
2
0
1.5k
Sep ’24
Mapkit and swiftui
I have updated my map code so that now I have a region that is set as a state var in my strict. My map links to this state var. the problem is now I want to update my map based on my long and last variables that are passed to the struct is there a way to do this - going crazy trying to do this
3
0
4.9k
Sep ’24
iOS 18 NavigationSplitView in NavigationStack not loading properly
With iOS 18.0, this snippet of code that has a NavigationSplitView inside a NavigationStack will not display the sidebar until the navigation transition is completed. NavigationStack { NavigationLink("Link") { NavigationSplitView { Text("Example") } detail: { Text("Does not appear") } } } Directly after pressing the link, a toolbar briefly appears. Once the transition is completed, the split view's sidebar appears and the toolbar disappears. The detail view does not visually appear at all. The same problem occurs when using .navigationDestination(…), which I am in our production code. I've tested this in Xcode 16.0 Previews for iOS 18.0, iPhone SE Simulator iOS 18.0, iPadOS 18.0 when horizontal size class is compact, and on my personal iPhone 13 mini iOS 18.0 I experienced this problem on our production app. Is there any workaround to not have this delay? Our app is heavily built around this nested approach, and has been working perfectly in previous iOS versions.
3
0
997
Sep ’24