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

Strange media player overlay main screen
Respected Madam/Sir, The following code works well in the past year, but when I test it again on my iPhone which run iOS 16.7.8, a strange media player appeared and overlay the main screen of my app, I really don't know what happened there, I'm struggling to resolve it hours, but it still always appear, help please! Any suggestion, direction, api misused, would be appreciated. let mainScreenController : ViewController = ViewController() self.window = UIWindow(frame: UIScreen.main.bounds) self.window?.rootViewController = mainScreenController self.window?.makeKeyAndVisible()
Topic: UI Frameworks SubTopic: UIKit
2
0
122
Apr ’25
iOS 18 SDK causing random UI changes and crashes with my app
I am a developer on an enterprise application. Our team just updated our pipeline to build our app on the iOS 18 SDK instead of the 17.4 SDK and this has caused a lot of our ui elements to change and several crashes within the app resulting in just the simple error message "Swift runtime failure: unhandled C++ / Objective-C exception". Why is just updating the SDK causing all these issues? Is there anyway to keep the previous version or will we have to go component by component to fix the constraints and crashes? These issues seem to be happening to our users on iOS 18 and beyond.
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
147
Apr ’25
Some questions about CarPlay UI and entitlement
I read this doc and find some key info. https://developer.apple.com/carplay/documentation/CarPlay-App-Programming-Guide.pdf CarPlay app entitlements All CarPlay apps require a CarPlay app entitlement that matches your app type. To request a CarPlay app entitlement, go to http://developer.apple.com/carplay and provide information about your app, including the type of entitlement that you are requesting. You also need to agree to the CarPlay Entitlement Addendum. Apple will review your request. If your app meets the criteria for a CarPlay app, Apple will assign a CarPlay app entitlement to your Apple Developer account and notify you. But I still have questions about the old and new CarPlay. // About account permission I have 2 Apple developer accounts. Account A (normal dev account): Here our app already supports the old-style CarPlay UI. (before iOS14) And I can see there are "CarPlay Messaging App" and "CarPlay VoIP Calling App" in the "Additional Capabilities" tab in my Identifier. Account B (Enterprise account): I can see there is a "CarPlay Communication App" in the "Additional Capabilities" tab in my Identifier. But I don't know (or don't remember) if I have requested this new CarPlay entitlement for this account. Quesiton 1: If I want to refactor my current CarPlay app (from old UI to new UI [iOS14 support]), Do I need to request the CarPlay entitlement for Account A? Because I can not find the "CarPlay Communication App" in Account A portal(or via Xcode). // About New CarPlay UI In the old UI, there are just 2 buttons showing after user tap the App icon now. One is for message and the other one is for VoIP call. But I can see only one VoIP call button in the new CarPlay UI, no seperated message button. Question2: Can I add a message button? If no, how to implement a similiar user experience. Thanks.
1
0
108
Apr ’25
HELP: App Clip Card Doesn't Appear!
I integrated an Advanced App Clip Experience to my app. In trying to test the App Clip Card, the card does not appear when I tap the link on my device that is associated to the Advanced App Clip Experience. Listed are some contextual information: Testing on device running on iOS 18.3.1 Associated Domains: Main target app: applinks: App clips target app: applinks: and appclips: Archived and uploaded build to App Store Connect. Green "Testing" status via Testflight. On Distribution tab, green "Valid" status for build domain. Advanced App Clip Experience green "Received" status. Developer App Clip Testing Diagnostics: Green "Register Advanced Experience" status Green "App Clip Code" status Warning "App Clip Published on App Store" Orange Circle "Associated Domains" After looking at countless threads, I still cannot for the life of me find a solution to test the App Clip. Any guidance would be extremely appreciated. I had also submitted a support ticket with case ID #102552504973.
12
0
611
Apr ’25
Animated scale effect causes NSCursor to reset in SwiftUI macOS app
For my macOS app, I'm trying to change the mouse cursor to a pointing hand while hovering over a specific view. However, when the view is scaled with an animation triggered by hovering (using .scaleEffect() and .animation()), the cursor doesn't change as expected. Is there any workaround to fix this? This is a sample code: struct ContentView: View { @State private var hovering = false var body: some View { VStack { Text("Hover me") .padding() .background(hovering ? Color.blue : Color.gray) .scaleEffect(hovering ? 1.2 : 1.0) .animation(.linear(duration: 0.2), value: hovering) .onHover { hovering in self.hovering = hovering if hovering { NSCursor.pointingHand.push() } else { NSCursor.pop() } } } .frame(width: 200, height: 200) } } This is how it works: As you can see, when the pointer enters the view, the cursor changes momentarily before reverting back to the arrow icon. I also tried using NSTrackingArea with an NSView placed over the view, but it did not solve the issue. It might be that the combination of .scaleEffect() and .animation() is causing a forced cursor reset (possibly related to the use of NSWindow.disableCursorRects() or something similar). However, I'm not entirely sure. Any insights or suggestions would be greatly appreciated. Thanks!
2
0
136
Apr ’25
Markdown Link in AttributedString Not Focusable with Full Keyboard Access in SwiftUI
I’m encountering an accessibility issue in SwiftUI related to keyboard navigation. 🐞 Problem When using an AttributedString to display Markdown content in a SwiftUI view (such as a Text view), any links included in the Markdown are not keyboard focusable when Full Keyboard Access is enabled. This means users can’t navigate to or activate the links using the Tab key or other keyboard-only methods. 💻 Platform iOS version: 16+ Framework: SwiftUI Device: All tested iPhones and iPads 🧪 Steps to Reproduce Enable Full Keyboard Access in iOS settings. Run the included SwiftUI Playground or equivalent app using the code below. Try to navigate to the link using Tab or keyboard arrow keys. Observe that the Markdown link is not reachable via keyboard focus. 🧩 Expected Behavior The Markdown link should be reachable via keyboard focus. It should be possible to activate the link using Space or Return. 📚 Example code struct ContentView: View { let attributedString: AttributedString init() { self.attributedString = try! AttributedString( markdown: "This is a [test link](https://apple.com) inside an attributed string." ) } var body: some View { VStack { Text("Issue: Attributed Markdown Link Is Not Focusable with full keyboard access") .font(.headline) .padding() Text(attributedString) // The link is not focusable with .padding() .border(Color.gray, width: 1) Text("Expected: The link should be focusable with Full Keyboard Access.") .foregroundColor(.red) .padding() } } }
1
3
172
Apr ’25
Memory leak using .onSubmit on TextField in SwiftU
I am getting memory leak when using .onSubmit view modifier on TextField. Here is a simplified reproducible example: struct ListView: View { var body: some View { NavigationStack { List(0..<100) { i in NavigationLink("Select \(i)", value: i) } .navigationDestination(for: Int.self) { selection in DetailView() .navigationTitle("Page: \(selection)") } } } } struct DetailView: View { @State private var viewModel = DetailViewModel() var body: some View { TextField( "", text: $viewModel.text, prompt: Text("Type in") ) .padding() .onSubmit { print(viewModel.text) } } } @Observable final class DetailViewModel { var text: String = "" deinit { print("Deinit \(Self.self)") } } Navigate to DetailView by selecting a row on ListView page and start typing in TextField, hit the submit button on keyboard and this DetailView with DetailViewModel will be leaked after navigating back to ListView, deinit will not be called. Commenting out .onSubmit {} part fixes the leak. What I observed also, is that once I open the same page or other, It will create new DetailView instance with it's view model and previously leaked one will be released, possible indicating that system somehow holds the last active TextField until new one has become active. I tried calling UIApplication.shared.resignFirstResponder() in onDissapear{} but this does not fix the leak. Only way the leak is fixed, is by using deprecated TextField initializer: init(_ titleKey: LocalizedStringKey, text: Binding<String>, onCommit: @escaping () -> Void) where onCommit is essentially doing the same as onSubmit.
3
1
298
Apr ’25
Should you access @State properties from an NSViewController (AppKit / SwiftUI Integration)?
I'm currently working on a project to integrate some SwiftUI components into an existing AppKit application. The application makes extensive use of NSViewControllers. I can easily bridge between AppKit and SwiftUI using a view model that conforms to ObservableObject and is shared between the NSViewController and the SwiftUI View. But it's kind of tedious creating a view model for every view. Is it "safe" and "acceptable" for the NSViewController to "hold on" to the SwiftUI View that it creates and then access its @State or @StateObject properties? The lifecycle of DetailsView, a SwiftUI View, isn't clear to me when viewed through the lens of an NSViewController. Consider the following: import AppKit import SwiftUI struct DetailsView: View { @State var details: String = "" var body: some View { Text(details) } } final class ViewController: NSViewController { private let detailsView: DetailsView init() { self.detailsView = DetailsView() super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { view.addSubview(NSHostingView(rootView: detailsView)) } func updateDetails(_ details: String) { // Is this 'safe' and 'acceptable'? self.detailsView.details = details } } Is the view controller guaranteed to always be updating the correct @State property or is there a chance that the view controller's reference to it somehow becomes stale because of a SwiftUI update?
2
0
138
Apr ’25
Can @Query and ModelActor co-exist? How?
Context: The SwiftUI @Query macro has an internal modelContext. The ModelActor also has a modelContext, from which the data should be read/written. Issue: When writing to @Model data fetched with @Query macro using a ModelActor, it will crash in the most not-obvious ways. Also, fetching @Model with ModelActor will result in errors in Swift 6 since @Model aren't sendable. Problem to Solve: - How to write a good amount of data to SwiftData/CoreData without blocking the UI thread? Would the recommendation from the Apple team be that a large amount of data should be read/written with ModelActor and a small amount should be done with the @Query's internal modelContext ?
1
0
154
Apr ’25
Can SwiftUI on macOS create an NSComboButton?
Without resorting to NSViewRepresentable, is there a view or view modifier in SwiftUI that can create an NSComboButton on macOS? NSComboButton was introduced in macOS 13 and is (relatively) new to AppKit: Apple Developer - NSComboButton I only require support on macOS for this control. Note that this is not to be confused with NSComboBox, which is a completely different control.
1
0
132
Apr ’25
Library not loaded: /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore
Hello. I'm building an iOS application that builds a framework named Design.framework using Xcode 16.1. When I launch my application on iOS 17.X, i get the following runtime error dyld[47899]: Library not loaded: /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore Referenced from: <E625A246-E36B-351A-B077-CC38BAB5E07B> /Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/Design.framework/Design Reason: tried: '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-watchsimulator/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-watchsimulator/PackageFrameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/PackageFrameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file, not in dyld cache), '/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file) This error does not happen on iOS 18+. When i run dyld_info Design.framework/Design, i see that there is indeed a dependency on SwiftUICore.framework Design.framework/Design [arm64]: -platform: platform minOS sdk iOS-simulator 16.0 18.1 -uuid: 09880F25-DC86-3D8E-BCAE-1A283508D879 -segments: load-offset segment section sect-size seg-size max-prot init-prot 0x00000000 __TEXT 416KB r.x 0x00000000 __TEXT 416KB r.x 0x0000543C __text 355508 0x0005C0F0 __stubs 3168 0x0005CD50 __objc_methlist 32 0x0005CD70 __const 8296 0x0005EDD8 __swift5_typeref 15820 0x00062BB0 __cstring 6885 0x00064698 __constg_swiftt 2804 0x0006518C __swift5_builtin 40 0x000651C0 __swift5_reflstr 2952 0x00065D48 __swift5_assocty 816 0x00066078 __objc_methname 299 0x000661A4 __swift5_proto 368 0x00066314 __swift5_types 280 0x0006642C __swift5_fieldmd 3688 0x00067294 __swift5_protos 8 0x0006729C __swift5_capture 244 0x00067390 __unwind_info 2296 0x00067C88 __eh_frame 888 0x00068000 __DATA_CONST 16KB rw. 0x00068000 __DATA_CONST 16KB rw. 0x00068000 __got 3704 0x00068E78 __const 6864 0x0006A948 __objc_classlist 40 0x0006A970 __objc_imageinfo 8 0x0006C000 __DATA 32KB rw. 0x0006C000 __DATA 32KB rw. 0x0006C000 __objc_const 792 0x0006C318 __objc_selrefs 96 0x0006C378 __objc_classrefs 48 0x0006C3A8 __objc_data 208 0x0006C478 __data 4136 0x0006D4A0 __bss 12784 0x00070690 __common 4592 -linked_dylibs: attributes load path @rpath/CommonTools.framework/CommonTools /System/Library/Frameworks/Foundation.framework/Foundation /usr/lib/libobjc.A.dylib /usr/lib/libSystem.B.dylib /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics /System/Library/Frameworks/CoreText.framework/CoreText weak-link /System/Library/Frameworks/DeveloperToolsSupport.framework/DeveloperToolsSupport /System/Library/Frameworks/SwiftUI.framework/SwiftUI /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore /System/Library/Frameworks/UIKit.framework/UIKit /usr/lib/swift/libswiftCore.dylib weak-link /usr/lib/swift/libswiftCoreAudio.dylib /usr/lib/swift/libswiftCoreFoundation.dylib weak-link /usr/lib/swift/libswiftCoreImage.dylib weak-link /usr/lib/swift/libswiftCoreMedia.dylib weak-link /usr/lib/swift/libswiftDarwin.dylib weak-link /usr/lib/swift/libswiftDataDetection.dylib weak-link /usr/lib/swift/libswiftDispatch.dylib weak-link /usr/lib/swift/libswiftFileProvider.dylib weak-link /usr/lib/swift/libswiftMetal.dylib weak-link /usr/lib/swift/libswiftOSLog.dylib /usr/lib/swift/libswiftObjectiveC.dylib weak-link /usr/lib/swift/libswiftQuartzCore.dylib weak-link /usr/lib/swift/libswiftSpatial.dylib weak-link /usr/lib/swift/libswiftUniformTypeIdentifiers.dylib weak-link /usr/lib/swift/libswiftXPC.dylib /usr/lib/swift/libswift_Concurrency.dylib weak-link /usr/lib/swift/libswiftos.dylib weak-link /usr/lib/swift/libswiftsimd.dylib weak-link /usr/lib/swift/libswiftUIKit.dylib I can add a -weak_framework SwiftUICore to "Other Linker Flags" in my Design.framework Build Settings, and that will solve my problem, but I'd like to know what prompts my Design.framework to depend on SwiftUICore despite having a minimum set to iOS 16? And how am I supposed to handle devices prior to iOS 18 which do not have this library? is adding the linker flag the right way forward?
Topic: UI Frameworks SubTopic: SwiftUI
5
0
1.5k
Apr ’25
SwiftUI/WatchOS - Picker inside a ScrollView does not work as expected
What I am trying to build Apple Watch app(written in SwiftUI, targeting watchOS 7 or higher, built with Xcode 14.1) The Problem Picker placed inside a ScrollView on an apple watch device does not work as expected I want to find out how to get the Picker to work as expected, stated below. Expected behavior On an iOS simulator, a Picker inside a ScrollView works as expected. If I try scroll interaction on the Picker area, the ScrollView part doesn’t get scrolled and only the Picker gets scrolled. whereas on the watch simulator Example, 

 If I try to scroll the Picker by touching the Picker area, the whole ScrollView reacts and moves up and down. And I am not able to control the Picker properly. The code I wrote is as follows: ScrollView { //..other view elements.. Picker(selection: $currentDay) { ForEach(weekDays, id: \.self) { Text($0) } } label: { Text("") } .frame(width: 148,height: 50) .pickerStyle(.wheel) //..other view elements.. }//: ScrollView Things I have tried putting the Picker inside a VStack/ZStack/HStack giving the Picker fixed frame values / giving other elements inside the ScrollView fixed frame values
2
1
2.1k
Apr ’25
Text is truncated with certain font sizes on iOS 17+, but not on iOS 16
’m experiencing an issue where a Text view is unexpectedly truncated with certain font sizes (e.g., .body) on iOS 17 and later. This does not occur on iOS 16. I’ve applied .fixedSize(horizontal: false, vertical: true) to allow the text to grow vertically, but it still doesn’t show the entire content. Depending on the text content or font size, it sometimes works, but not always. How can I ensure the full text is displayed correctly on iOS 17+? Here is a minimal reproducible SwiftUI example: let sampleText1 = """ これはサンプルのテキストです、 ・箇条書き1 ・箇条書き2 であかさたなクロを送り、 アアを『ああああいいいい』フライパンに入れ、あかさたなです😋 """ let sampleText2 = """ 【旬|最高級】北海道産 生サンマ 釜飯 ----- Aaa iii uuu """ struct ContentView: View { var body: some View { ScrollView { VStack(alignment: .leading, spacing: 10) { HStack { MessageTextView(text: sampleText1) .layoutPriority(100) Spacer() } HStack { MessageTextView(text: sampleText2) .layoutPriority(100) Spacer() } } } } } struct MessageTextView: View { var text: String var body: some View { Text(text) .fixedSize(horizontal: false, vertical: true) .font(.body) .padding(.leading, 16) .padding(.trailing, 16) .padding(.top, 8) .padding(.bottom, 8) } } img1 img2
4
0
188
Apr ’25
Improving references to localized strings in App Intents
In order to make referencing keys for localized strings a little more reliable, our application references generated constants for localized string keys: This eliminates the potential for developers to misspell a key when referencing a localized strings. And because these constants are automatically generated by the exact same process that provides localized strings for the application, each and every constant is guaranteed to have a localized string associated with it. I’m currently attempting to implement something similar for the localized strings referenced by our new App Intents. Our initial release of App Intent functionality is simply using string literals to reference localized strings: However, I am running into several issues when trying to reference the string keys as a constant. The closest I managed to get was defining the constant as either a LocalizationValue or as a StaticString and referencing the constant while initializing the LocalizedStringResource. With this approach, I see no errors from Xcode until I try and compile. What’s more is that the wording of the error being thrown is quite peculiar: As you can see with the sample code above, I am clearly calling LocalizedStringResource’s initializer directly as Indicated by the error. Is what I’m trying to do even possible with App Intents? From my research, it does look like iOS app localization is moving more towards using string literals for localized strings. Like with String Catalog’s ability to automatically generate entries from strings referenced in UI without the need for a key. However, we’d prefer to use constants if possible for the reasons listed above.
0
0
138
Apr ’25
NavigationStack + navigationDestination issue in
Hi everyone, this is my first post. I'm facing an issue that I don't fully understand. The problem started once I migrated to use NavigationStack instead of navigation View. I have a View, let's called "NextWeekView" where I do some async process onAppear, calling an async function from the "NextWeekViewModel". Depending on the result of this processing, I need to navigate automatically to different Views. I use @Published variables on the ViewModel that I populate with the destination view. Once the processing is finish, on the View and still on onAppear, I enable a @State navigate, and return the destination View based on the @Publish: The View enum DestinationType { case play case menu case endseason } struct NextWeekView: View { @ObservedObject var team: Team @StateObject var nextWeekViewModel = NextWeekViewModel() @State private var destination: DestinationType? = nil @State var navigate: Bool = false var body: some View { LoadingScreenView(text: self.nextWeekViewModel.currentStep) .navigationDestination(isPresented: self.$navigate) { destinationView(for: self.nextWeekViewModel.destination) } .navigationBarHidden(true) .statusBar(hidden: true) .onAppear{ Task { await nextWeekViewModel.processNextWeek(team: team) if nextWeekViewModel.finishedProcessing { self.navigate.toggle() } print("navigate to: \(self.navigation)") // debug, it always print the expected value. } } } // Function to return the appropriate view based on the destination @ViewBuilder private func destinationView(for destination: DestinationType?) -> some View { switch destination { case .play: MatchPlayView(team: self.team) case .menu: GameMenuView().environmentObject(team) case .endseason: SeasonEndView().environmentObject(team) case .none: EmptyView() } } } The ViewModel class NextWeekViewModel: ObservableObject { var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext let backgroundContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType) @Published var currentStep:LocalizedStringKey = "" @Published var destination: DestinationType? = .menu @Published var finishedProcessing: Bool = false @MainActor func processNextWeek(team: Team) async { .... if currentWeek.matchdays.filter({ md in return md.num > currentWeek.current_matchday }).count == 0 { await self.endWeekProcess() // We check if it is end of season if currentSeason.current_week == currentSeason.weeks.count && currentWeek.matchdays.filter({ md in return md.num > currentWeek.current_matchday }).count == 0 { // End of season await self.endSeasonProcess(team: team, currentSeason: currentSeason) self.destination = .endseason // WORKS } else { // We go next week self.currentStep = "Create cash operations" await self.createCashOperations(team: team, week: currentSeason.current_week) self.currentStep = "Create messages" await self.createMessages(team: team) self.destination = .menu //WORKS } } else { print("Ther are more matchdays, lets pass the matchday") // THIS DOES NOT WORK // Any Modifications of destination is reflected on the view, but automatic navigation is not taking place self.destination = .play //self.destination = .menu // this also do not work. } self.finishedProcessing = true } What's happens: The code works when app goes through code path marked as //WORKS but not when follows code path //DO NOT WORK. Interestingly, it works perfectly on iOS 18. But not in iOS16/iOS17. If I add an interactive NavigationLink instead of the navigationDestination in the View : if self.nextWeekViewModel.finishedProcessing { NavigationLink(destination:destinationView(for: self.nextWeekViewModel.destination)){ SimpleButtonWithIconView(icon: "chevron.right.2", text: "Next") .padding(.bottom, 10) } } Then it works as expected but I really want to avoid the user to tap Next for a seamlessly gameplay I've tried all combinations of state variables, using different state variables per destination, but I always arrive to the same situation. I also printed everything left and right and View values looks consistent so I think the ViewModel is doing the right thing (also with the NavigationLink it works). It's simply that the "automatic" navigation does not want to navigate in certain occasions. I'm completely out of ideas. Any feedback will be welcomed. Otherwise I will revert back to NavigationView. Thank you in advance!
Topic: UI Frameworks SubTopic: SwiftUI
3
0
173
Apr ’25
I think I found a bug in SwiftUI on macOS 15.4 that crashes apps
We've been receiving crash reports for our app from users that have upgraded to macOS 15.4. I have upgraded my developer machine and immediately was able to reproduce the crash. I was able to create a minimal reproducible scenario. The following view crashes the app when sheet is presented with this trace: The window has been marked as needing another Update Constraints in Window pass, but it has already had more Update Constraints in Window passes than there are views in the window. <_TtC7SwiftUIP33_7B5508BFB2B0CAF1E28E206F2014E66B23SheetPresentationWindow: 0x1111074c0> 0x9bd (2493) {{0, 0}, {100, 108}} en ( 0 CoreFoundation 0x000000018bdfddf0 __exceptionPreprocess + 176 1 libobjc.A.dylib 0x000000018b8c2b60 objc_exception_throw + 88 2 CoreFoundation 0x000000018bdfdce0 +[NSException exceptionWithName:reason:userInfo:] + 0 3 AppKit 0x000000019043d394 -[NSWindow(NSDisplayCycle) _postWindowNeedsUpdateConstraints] + 1788 4 AppKit 0x000000018f9f8c08 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64 5 AppKit 0x000000018f9f8b8c -[NSView setNeedsUpdateConstraints:] + 468 6 SwiftUI 0x00000001bc0e5110 $s7SwiftUI13NSHostingViewC14setNeedsUpdate33_32B6F54841135BB466A5C1362EB89D05LLyyF + 80 7 SwiftUI 0x00000001bc101f28 $s7SwiftUI13NSHostingViewC13requestUpdate5afterySd_tF + 616 Conditions that are important: accessing a publishable property inside the sheet .sheet() on a component that is wrapped in another (VStack is required in the example provided) being used inside NavigationSplitView Presents of @Environment(\.openURL. Doesn't have to be used, simply present on the view. struct ContentView: View { @Environment(\.openURL) private var open @State var who = "world" @State var shown = false var body: some View { NavigationSplitView(sidebar: { Text("Hello, world") }, detail: { VStack(spacing: 20) { Button("Kill me pls") { shown = true } .frame(width: 110, height: 110) .sheet(isPresented: $shown) { VStack { HStack() { Text("Hello, \(who)!") } } .presentationBackground(.thinMaterial) } } }) } }
2
0
164
Apr ’25
Printing NSTextStorage over multiple UITextView produces weird results
I would like to print a NSTextStorage on multiple pages and add annotations to the side margins corresponding to certain text ranges. For example, for all occurrences of # at the start of a line, the side margin should show an automatically increasing number. My idea was to create a NSLayoutManager and dynamically add NSTextContainer instances to it until all text is laid out. The layoutManager would then allow me to get the bounding rectangle of the interesting text ranges so that I can draw the corresponding numbers at the same height inside the side margin. This approach works well on macOS, but I'm having some issues on iOS. When running the code below in an iPad Simulator, I would expect that the print preview shows 3 pages, the first with the numbers 0-1, the second with the numbers 2-3, and the last one with the number 4. Instead the first page shows the number 4, the second one the numbers 2-4, and the last one the numbers 0-4. It's as if the pages are inverted, and each page shows the text starting at the correct location but always ending at the end of the complete text (and not the range assigned to the relative textContainer). I've created FB17026419. class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { let printController = UIPrintInteractionController.shared let printPageRenderer = PrintPageRenderer() printPageRenderer.pageSize = CGSize(width: 100, height: 100) printPageRenderer.textStorage = NSTextStorage(string: (0..<5).map({ "\($0)" }).joined(separator: "\n"), attributes: [.font: UIFont.systemFont(ofSize: 30)]) printController.printPageRenderer = printPageRenderer printController.present(animated: true) { _, _, error in if let error = error { print(error.localizedDescription) } } } } class PrintPageRenderer: UIPrintPageRenderer, NSLayoutManagerDelegate { var pageSize: CGSize! var textStorage: NSTextStorage! private let layoutManager = NSLayoutManager() private var textViews = [UITextView]() override var numberOfPages: Int { if !Thread.isMainThread { return DispatchQueue.main.sync { [self] in numberOfPages } } printFormatters = nil layoutManager.delegate = self textStorage.addLayoutManager(layoutManager) if textStorage.length > 0 { let glyphRange = layoutManager.glyphRange(forCharacterRange: NSRange(location: textStorage.length - 1, length: 0), actualCharacterRange: nil) layoutManager.textContainer(forGlyphAt: glyphRange.location, effectiveRange: nil) } var page = 0 for textView in textViews { let printFormatter = textView.viewPrintFormatter() addPrintFormatter(printFormatter, startingAtPageAt: page) page += printFormatter.pageCount } return page } func layoutManager(_ layoutManager: NSLayoutManager, didCompleteLayoutFor textContainer: NSTextContainer?, atEnd layoutFinishedFlag: Bool) { if textContainer == nil { addPage() } } private func addPage() { let textContainer = NSTextContainer(size: pageSize) layoutManager.addTextContainer(textContainer) let textView = UITextView(frame: CGRect(origin: .zero, size: pageSize), textContainer: textContainer) textViews.append(textView) } }
Topic: UI Frameworks SubTopic: UIKit Tags:
4
0
127
Apr ’25
Transforming RealityKit entities using gestures
In the section : Add transform logic to the main component There is the line : var state: GestureStateComponent = entity.gestureStateComponent ?? GestureStateComponent() When I try to add the same line. I have the error cannot find GestureStateComponent in scope. My imports : import SwiftUI import RealityKit import RealityKitContent An answer would be greatly appreciate it
2
0
78
Apr ’25
iOS17 UITextView inputView becomFirstResponder does not work
Simplely, when we set UITextView.inputView and then call becomeFirstResponder, but the custom inputView could not show expectedly just like before. We test this code in iOS17 and below, while only iOS17 does not work. And xcode console print these logs: Failed to retrieve snapshot. -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked:
49
17
37k
Apr ’25
Strange media player overlay main screen
Respected Madam/Sir, The following code works well in the past year, but when I test it again on my iPhone which run iOS 16.7.8, a strange media player appeared and overlay the main screen of my app, I really don't know what happened there, I'm struggling to resolve it hours, but it still always appear, help please! Any suggestion, direction, api misused, would be appreciated. let mainScreenController : ViewController = ViewController() self.window = UIWindow(frame: UIScreen.main.bounds) self.window?.rootViewController = mainScreenController self.window?.makeKeyAndVisible()
Topic: UI Frameworks SubTopic: UIKit
Replies
2
Boosts
0
Views
122
Activity
Apr ’25
iOS 18 SDK causing random UI changes and crashes with my app
I am a developer on an enterprise application. Our team just updated our pipeline to build our app on the iOS 18 SDK instead of the 17.4 SDK and this has caused a lot of our ui elements to change and several crashes within the app resulting in just the simple error message "Swift runtime failure: unhandled C++ / Objective-C exception". Why is just updating the SDK causing all these issues? Is there anyway to keep the previous version or will we have to go component by component to fix the constraints and crashes? These issues seem to be happening to our users on iOS 18 and beyond.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
0
Boosts
0
Views
147
Activity
Apr ’25
Some questions about CarPlay UI and entitlement
I read this doc and find some key info. https://developer.apple.com/carplay/documentation/CarPlay-App-Programming-Guide.pdf CarPlay app entitlements All CarPlay apps require a CarPlay app entitlement that matches your app type. To request a CarPlay app entitlement, go to http://developer.apple.com/carplay and provide information about your app, including the type of entitlement that you are requesting. You also need to agree to the CarPlay Entitlement Addendum. Apple will review your request. If your app meets the criteria for a CarPlay app, Apple will assign a CarPlay app entitlement to your Apple Developer account and notify you. But I still have questions about the old and new CarPlay. // About account permission I have 2 Apple developer accounts. Account A (normal dev account): Here our app already supports the old-style CarPlay UI. (before iOS14) And I can see there are "CarPlay Messaging App" and "CarPlay VoIP Calling App" in the "Additional Capabilities" tab in my Identifier. Account B (Enterprise account): I can see there is a "CarPlay Communication App" in the "Additional Capabilities" tab in my Identifier. But I don't know (or don't remember) if I have requested this new CarPlay entitlement for this account. Quesiton 1: If I want to refactor my current CarPlay app (from old UI to new UI [iOS14 support]), Do I need to request the CarPlay entitlement for Account A? Because I can not find the "CarPlay Communication App" in Account A portal(or via Xcode). // About New CarPlay UI In the old UI, there are just 2 buttons showing after user tap the App icon now. One is for message and the other one is for VoIP call. But I can see only one VoIP call button in the new CarPlay UI, no seperated message button. Question2: Can I add a message button? If no, how to implement a similiar user experience. Thanks.
Replies
1
Boosts
0
Views
108
Activity
Apr ’25
HELP: App Clip Card Doesn't Appear!
I integrated an Advanced App Clip Experience to my app. In trying to test the App Clip Card, the card does not appear when I tap the link on my device that is associated to the Advanced App Clip Experience. Listed are some contextual information: Testing on device running on iOS 18.3.1 Associated Domains: Main target app: applinks: App clips target app: applinks: and appclips: Archived and uploaded build to App Store Connect. Green "Testing" status via Testflight. On Distribution tab, green "Valid" status for build domain. Advanced App Clip Experience green "Received" status. Developer App Clip Testing Diagnostics: Green "Register Advanced Experience" status Green "App Clip Code" status Warning "App Clip Published on App Store" Orange Circle "Associated Domains" After looking at countless threads, I still cannot for the life of me find a solution to test the App Clip. Any guidance would be extremely appreciated. I had also submitted a support ticket with case ID #102552504973.
Replies
12
Boosts
0
Views
611
Activity
Apr ’25
Animated scale effect causes NSCursor to reset in SwiftUI macOS app
For my macOS app, I'm trying to change the mouse cursor to a pointing hand while hovering over a specific view. However, when the view is scaled with an animation triggered by hovering (using .scaleEffect() and .animation()), the cursor doesn't change as expected. Is there any workaround to fix this? This is a sample code: struct ContentView: View { @State private var hovering = false var body: some View { VStack { Text("Hover me") .padding() .background(hovering ? Color.blue : Color.gray) .scaleEffect(hovering ? 1.2 : 1.0) .animation(.linear(duration: 0.2), value: hovering) .onHover { hovering in self.hovering = hovering if hovering { NSCursor.pointingHand.push() } else { NSCursor.pop() } } } .frame(width: 200, height: 200) } } This is how it works: As you can see, when the pointer enters the view, the cursor changes momentarily before reverting back to the arrow icon. I also tried using NSTrackingArea with an NSView placed over the view, but it did not solve the issue. It might be that the combination of .scaleEffect() and .animation() is causing a forced cursor reset (possibly related to the use of NSWindow.disableCursorRects() or something similar). However, I'm not entirely sure. Any insights or suggestions would be greatly appreciated. Thanks!
Replies
2
Boosts
0
Views
136
Activity
Apr ’25
My first Xcode build ever But EXC_BAD_ACCESS (code=2, address=0x16e837f30) keeps happening
I Am interested in coding, and built my fist app that is an app that has a picture of Niagara Falls with corner radius of 10, But, every time I start the build, it says: Thread 1: EXC_BAD_ACCESS (code=2, address=0x16b123f20) not sure what to do now.
Replies
7
Boosts
0
Views
156
Activity
Apr ’25
Markdown Link in AttributedString Not Focusable with Full Keyboard Access in SwiftUI
I’m encountering an accessibility issue in SwiftUI related to keyboard navigation. 🐞 Problem When using an AttributedString to display Markdown content in a SwiftUI view (such as a Text view), any links included in the Markdown are not keyboard focusable when Full Keyboard Access is enabled. This means users can’t navigate to or activate the links using the Tab key or other keyboard-only methods. 💻 Platform iOS version: 16+ Framework: SwiftUI Device: All tested iPhones and iPads 🧪 Steps to Reproduce Enable Full Keyboard Access in iOS settings. Run the included SwiftUI Playground or equivalent app using the code below. Try to navigate to the link using Tab or keyboard arrow keys. Observe that the Markdown link is not reachable via keyboard focus. 🧩 Expected Behavior The Markdown link should be reachable via keyboard focus. It should be possible to activate the link using Space or Return. 📚 Example code struct ContentView: View { let attributedString: AttributedString init() { self.attributedString = try! AttributedString( markdown: "This is a [test link](https://apple.com) inside an attributed string." ) } var body: some View { VStack { Text("Issue: Attributed Markdown Link Is Not Focusable with full keyboard access") .font(.headline) .padding() Text(attributedString) // The link is not focusable with .padding() .border(Color.gray, width: 1) Text("Expected: The link should be focusable with Full Keyboard Access.") .foregroundColor(.red) .padding() } } }
Replies
1
Boosts
3
Views
172
Activity
Apr ’25
Memory leak using .onSubmit on TextField in SwiftU
I am getting memory leak when using .onSubmit view modifier on TextField. Here is a simplified reproducible example: struct ListView: View { var body: some View { NavigationStack { List(0..<100) { i in NavigationLink("Select \(i)", value: i) } .navigationDestination(for: Int.self) { selection in DetailView() .navigationTitle("Page: \(selection)") } } } } struct DetailView: View { @State private var viewModel = DetailViewModel() var body: some View { TextField( "", text: $viewModel.text, prompt: Text("Type in") ) .padding() .onSubmit { print(viewModel.text) } } } @Observable final class DetailViewModel { var text: String = "" deinit { print("Deinit \(Self.self)") } } Navigate to DetailView by selecting a row on ListView page and start typing in TextField, hit the submit button on keyboard and this DetailView with DetailViewModel will be leaked after navigating back to ListView, deinit will not be called. Commenting out .onSubmit {} part fixes the leak. What I observed also, is that once I open the same page or other, It will create new DetailView instance with it's view model and previously leaked one will be released, possible indicating that system somehow holds the last active TextField until new one has become active. I tried calling UIApplication.shared.resignFirstResponder() in onDissapear{} but this does not fix the leak. Only way the leak is fixed, is by using deprecated TextField initializer: init(_ titleKey: LocalizedStringKey, text: Binding<String>, onCommit: @escaping () -> Void) where onCommit is essentially doing the same as onSubmit.
Replies
3
Boosts
1
Views
298
Activity
Apr ’25
Should you access @State properties from an NSViewController (AppKit / SwiftUI Integration)?
I'm currently working on a project to integrate some SwiftUI components into an existing AppKit application. The application makes extensive use of NSViewControllers. I can easily bridge between AppKit and SwiftUI using a view model that conforms to ObservableObject and is shared between the NSViewController and the SwiftUI View. But it's kind of tedious creating a view model for every view. Is it "safe" and "acceptable" for the NSViewController to "hold on" to the SwiftUI View that it creates and then access its @State or @StateObject properties? The lifecycle of DetailsView, a SwiftUI View, isn't clear to me when viewed through the lens of an NSViewController. Consider the following: import AppKit import SwiftUI struct DetailsView: View { @State var details: String = "" var body: some View { Text(details) } } final class ViewController: NSViewController { private let detailsView: DetailsView init() { self.detailsView = DetailsView() super.init(nibName: nil, bundle: nil) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { view.addSubview(NSHostingView(rootView: detailsView)) } func updateDetails(_ details: String) { // Is this 'safe' and 'acceptable'? self.detailsView.details = details } } Is the view controller guaranteed to always be updating the correct @State property or is there a chance that the view controller's reference to it somehow becomes stale because of a SwiftUI update?
Replies
2
Boosts
0
Views
138
Activity
Apr ’25
Can @Query and ModelActor co-exist? How?
Context: The SwiftUI @Query macro has an internal modelContext. The ModelActor also has a modelContext, from which the data should be read/written. Issue: When writing to @Model data fetched with @Query macro using a ModelActor, it will crash in the most not-obvious ways. Also, fetching @Model with ModelActor will result in errors in Swift 6 since @Model aren't sendable. Problem to Solve: - How to write a good amount of data to SwiftData/CoreData without blocking the UI thread? Would the recommendation from the Apple team be that a large amount of data should be read/written with ModelActor and a small amount should be done with the @Query's internal modelContext ?
Replies
1
Boosts
0
Views
154
Activity
Apr ’25
Can SwiftUI on macOS create an NSComboButton?
Without resorting to NSViewRepresentable, is there a view or view modifier in SwiftUI that can create an NSComboButton on macOS? NSComboButton was introduced in macOS 13 and is (relatively) new to AppKit: Apple Developer - NSComboButton I only require support on macOS for this control. Note that this is not to be confused with NSComboBox, which is a completely different control.
Replies
1
Boosts
0
Views
132
Activity
Apr ’25
Library not loaded: /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore
Hello. I'm building an iOS application that builds a framework named Design.framework using Xcode 16.1. When I launch my application on iOS 17.X, i get the following runtime error dyld[47899]: Library not loaded: /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore Referenced from: <E625A246-E36B-351A-B077-CC38BAB5E07B> /Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/Design.framework/Design Reason: tried: '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-watchsimulator/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-watchsimulator/PackageFrameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/Users/v/Library/Developer/Xcode/DerivedData/iScribd-bexojbdreldwkvbpzioqueldnvng/Build/Products/Debug_AppStore-iphonesimulator/PackageFrameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file), '/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file, not in dyld cache), '/Library/Developer/CoreSimulator/Volumes/iOS_21C62/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore' (no such file) This error does not happen on iOS 18+. When i run dyld_info Design.framework/Design, i see that there is indeed a dependency on SwiftUICore.framework Design.framework/Design [arm64]: -platform: platform minOS sdk iOS-simulator 16.0 18.1 -uuid: 09880F25-DC86-3D8E-BCAE-1A283508D879 -segments: load-offset segment section sect-size seg-size max-prot init-prot 0x00000000 __TEXT 416KB r.x 0x00000000 __TEXT 416KB r.x 0x0000543C __text 355508 0x0005C0F0 __stubs 3168 0x0005CD50 __objc_methlist 32 0x0005CD70 __const 8296 0x0005EDD8 __swift5_typeref 15820 0x00062BB0 __cstring 6885 0x00064698 __constg_swiftt 2804 0x0006518C __swift5_builtin 40 0x000651C0 __swift5_reflstr 2952 0x00065D48 __swift5_assocty 816 0x00066078 __objc_methname 299 0x000661A4 __swift5_proto 368 0x00066314 __swift5_types 280 0x0006642C __swift5_fieldmd 3688 0x00067294 __swift5_protos 8 0x0006729C __swift5_capture 244 0x00067390 __unwind_info 2296 0x00067C88 __eh_frame 888 0x00068000 __DATA_CONST 16KB rw. 0x00068000 __DATA_CONST 16KB rw. 0x00068000 __got 3704 0x00068E78 __const 6864 0x0006A948 __objc_classlist 40 0x0006A970 __objc_imageinfo 8 0x0006C000 __DATA 32KB rw. 0x0006C000 __DATA 32KB rw. 0x0006C000 __objc_const 792 0x0006C318 __objc_selrefs 96 0x0006C378 __objc_classrefs 48 0x0006C3A8 __objc_data 208 0x0006C478 __data 4136 0x0006D4A0 __bss 12784 0x00070690 __common 4592 -linked_dylibs: attributes load path @rpath/CommonTools.framework/CommonTools /System/Library/Frameworks/Foundation.framework/Foundation /usr/lib/libobjc.A.dylib /usr/lib/libSystem.B.dylib /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation /System/Library/Frameworks/CoreGraphics.framework/CoreGraphics /System/Library/Frameworks/CoreText.framework/CoreText weak-link /System/Library/Frameworks/DeveloperToolsSupport.framework/DeveloperToolsSupport /System/Library/Frameworks/SwiftUI.framework/SwiftUI /System/Library/Frameworks/SwiftUICore.framework/SwiftUICore /System/Library/Frameworks/UIKit.framework/UIKit /usr/lib/swift/libswiftCore.dylib weak-link /usr/lib/swift/libswiftCoreAudio.dylib /usr/lib/swift/libswiftCoreFoundation.dylib weak-link /usr/lib/swift/libswiftCoreImage.dylib weak-link /usr/lib/swift/libswiftCoreMedia.dylib weak-link /usr/lib/swift/libswiftDarwin.dylib weak-link /usr/lib/swift/libswiftDataDetection.dylib weak-link /usr/lib/swift/libswiftDispatch.dylib weak-link /usr/lib/swift/libswiftFileProvider.dylib weak-link /usr/lib/swift/libswiftMetal.dylib weak-link /usr/lib/swift/libswiftOSLog.dylib /usr/lib/swift/libswiftObjectiveC.dylib weak-link /usr/lib/swift/libswiftQuartzCore.dylib weak-link /usr/lib/swift/libswiftSpatial.dylib weak-link /usr/lib/swift/libswiftUniformTypeIdentifiers.dylib weak-link /usr/lib/swift/libswiftXPC.dylib /usr/lib/swift/libswift_Concurrency.dylib weak-link /usr/lib/swift/libswiftos.dylib weak-link /usr/lib/swift/libswiftsimd.dylib weak-link /usr/lib/swift/libswiftUIKit.dylib I can add a -weak_framework SwiftUICore to "Other Linker Flags" in my Design.framework Build Settings, and that will solve my problem, but I'd like to know what prompts my Design.framework to depend on SwiftUICore despite having a minimum set to iOS 16? And how am I supposed to handle devices prior to iOS 18 which do not have this library? is adding the linker flag the right way forward?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
5
Boosts
0
Views
1.5k
Activity
Apr ’25
SwiftUI/WatchOS - Picker inside a ScrollView does not work as expected
What I am trying to build Apple Watch app(written in SwiftUI, targeting watchOS 7 or higher, built with Xcode 14.1) The Problem Picker placed inside a ScrollView on an apple watch device does not work as expected I want to find out how to get the Picker to work as expected, stated below. Expected behavior On an iOS simulator, a Picker inside a ScrollView works as expected. If I try scroll interaction on the Picker area, the ScrollView part doesn’t get scrolled and only the Picker gets scrolled. whereas on the watch simulator Example, 

 If I try to scroll the Picker by touching the Picker area, the whole ScrollView reacts and moves up and down. And I am not able to control the Picker properly. The code I wrote is as follows: ScrollView { //..other view elements.. Picker(selection: $currentDay) { ForEach(weekDays, id: \.self) { Text($0) } } label: { Text("") } .frame(width: 148,height: 50) .pickerStyle(.wheel) //..other view elements.. }//: ScrollView Things I have tried putting the Picker inside a VStack/ZStack/HStack giving the Picker fixed frame values / giving other elements inside the ScrollView fixed frame values
Replies
2
Boosts
1
Views
2.1k
Activity
Apr ’25
Text is truncated with certain font sizes on iOS 17+, but not on iOS 16
’m experiencing an issue where a Text view is unexpectedly truncated with certain font sizes (e.g., .body) on iOS 17 and later. This does not occur on iOS 16. I’ve applied .fixedSize(horizontal: false, vertical: true) to allow the text to grow vertically, but it still doesn’t show the entire content. Depending on the text content or font size, it sometimes works, but not always. How can I ensure the full text is displayed correctly on iOS 17+? Here is a minimal reproducible SwiftUI example: let sampleText1 = """ これはサンプルのテキストです、 ・箇条書き1 ・箇条書き2 であかさたなクロを送り、 アアを『ああああいいいい』フライパンに入れ、あかさたなです😋 """ let sampleText2 = """ 【旬|最高級】北海道産 生サンマ 釜飯 ----- Aaa iii uuu """ struct ContentView: View { var body: some View { ScrollView { VStack(alignment: .leading, spacing: 10) { HStack { MessageTextView(text: sampleText1) .layoutPriority(100) Spacer() } HStack { MessageTextView(text: sampleText2) .layoutPriority(100) Spacer() } } } } } struct MessageTextView: View { var text: String var body: some View { Text(text) .fixedSize(horizontal: false, vertical: true) .font(.body) .padding(.leading, 16) .padding(.trailing, 16) .padding(.top, 8) .padding(.bottom, 8) } } img1 img2
Replies
4
Boosts
0
Views
188
Activity
Apr ’25
Improving references to localized strings in App Intents
In order to make referencing keys for localized strings a little more reliable, our application references generated constants for localized string keys: This eliminates the potential for developers to misspell a key when referencing a localized strings. And because these constants are automatically generated by the exact same process that provides localized strings for the application, each and every constant is guaranteed to have a localized string associated with it. I’m currently attempting to implement something similar for the localized strings referenced by our new App Intents. Our initial release of App Intent functionality is simply using string literals to reference localized strings: However, I am running into several issues when trying to reference the string keys as a constant. The closest I managed to get was defining the constant as either a LocalizationValue or as a StaticString and referencing the constant while initializing the LocalizedStringResource. With this approach, I see no errors from Xcode until I try and compile. What’s more is that the wording of the error being thrown is quite peculiar: As you can see with the sample code above, I am clearly calling LocalizedStringResource’s initializer directly as Indicated by the error. Is what I’m trying to do even possible with App Intents? From my research, it does look like iOS app localization is moving more towards using string literals for localized strings. Like with String Catalog’s ability to automatically generate entries from strings referenced in UI without the need for a key. However, we’d prefer to use constants if possible for the reasons listed above.
Replies
0
Boosts
0
Views
138
Activity
Apr ’25
NavigationStack + navigationDestination issue in
Hi everyone, this is my first post. I'm facing an issue that I don't fully understand. The problem started once I migrated to use NavigationStack instead of navigation View. I have a View, let's called "NextWeekView" where I do some async process onAppear, calling an async function from the "NextWeekViewModel". Depending on the result of this processing, I need to navigate automatically to different Views. I use @Published variables on the ViewModel that I populate with the destination view. Once the processing is finish, on the View and still on onAppear, I enable a @State navigate, and return the destination View based on the @Publish: The View enum DestinationType { case play case menu case endseason } struct NextWeekView: View { @ObservedObject var team: Team @StateObject var nextWeekViewModel = NextWeekViewModel() @State private var destination: DestinationType? = nil @State var navigate: Bool = false var body: some View { LoadingScreenView(text: self.nextWeekViewModel.currentStep) .navigationDestination(isPresented: self.$navigate) { destinationView(for: self.nextWeekViewModel.destination) } .navigationBarHidden(true) .statusBar(hidden: true) .onAppear{ Task { await nextWeekViewModel.processNextWeek(team: team) if nextWeekViewModel.finishedProcessing { self.navigate.toggle() } print("navigate to: \(self.navigation)") // debug, it always print the expected value. } } } // Function to return the appropriate view based on the destination @ViewBuilder private func destinationView(for destination: DestinationType?) -> some View { switch destination { case .play: MatchPlayView(team: self.team) case .menu: GameMenuView().environmentObject(team) case .endseason: SeasonEndView().environmentObject(team) case .none: EmptyView() } } } The ViewModel class NextWeekViewModel: ObservableObject { var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext let backgroundContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType) @Published var currentStep:LocalizedStringKey = "" @Published var destination: DestinationType? = .menu @Published var finishedProcessing: Bool = false @MainActor func processNextWeek(team: Team) async { .... if currentWeek.matchdays.filter({ md in return md.num > currentWeek.current_matchday }).count == 0 { await self.endWeekProcess() // We check if it is end of season if currentSeason.current_week == currentSeason.weeks.count && currentWeek.matchdays.filter({ md in return md.num > currentWeek.current_matchday }).count == 0 { // End of season await self.endSeasonProcess(team: team, currentSeason: currentSeason) self.destination = .endseason // WORKS } else { // We go next week self.currentStep = "Create cash operations" await self.createCashOperations(team: team, week: currentSeason.current_week) self.currentStep = "Create messages" await self.createMessages(team: team) self.destination = .menu //WORKS } } else { print("Ther are more matchdays, lets pass the matchday") // THIS DOES NOT WORK // Any Modifications of destination is reflected on the view, but automatic navigation is not taking place self.destination = .play //self.destination = .menu // this also do not work. } self.finishedProcessing = true } What's happens: The code works when app goes through code path marked as //WORKS but not when follows code path //DO NOT WORK. Interestingly, it works perfectly on iOS 18. But not in iOS16/iOS17. If I add an interactive NavigationLink instead of the navigationDestination in the View : if self.nextWeekViewModel.finishedProcessing { NavigationLink(destination:destinationView(for: self.nextWeekViewModel.destination)){ SimpleButtonWithIconView(icon: "chevron.right.2", text: "Next") .padding(.bottom, 10) } } Then it works as expected but I really want to avoid the user to tap Next for a seamlessly gameplay I've tried all combinations of state variables, using different state variables per destination, but I always arrive to the same situation. I also printed everything left and right and View values looks consistent so I think the ViewModel is doing the right thing (also with the NavigationLink it works). It's simply that the "automatic" navigation does not want to navigate in certain occasions. I'm completely out of ideas. Any feedback will be welcomed. Otherwise I will revert back to NavigationView. Thank you in advance!
Topic: UI Frameworks SubTopic: SwiftUI
Replies
3
Boosts
0
Views
173
Activity
Apr ’25
I think I found a bug in SwiftUI on macOS 15.4 that crashes apps
We've been receiving crash reports for our app from users that have upgraded to macOS 15.4. I have upgraded my developer machine and immediately was able to reproduce the crash. I was able to create a minimal reproducible scenario. The following view crashes the app when sheet is presented with this trace: The window has been marked as needing another Update Constraints in Window pass, but it has already had more Update Constraints in Window passes than there are views in the window. <_TtC7SwiftUIP33_7B5508BFB2B0CAF1E28E206F2014E66B23SheetPresentationWindow: 0x1111074c0> 0x9bd (2493) {{0, 0}, {100, 108}} en ( 0 CoreFoundation 0x000000018bdfddf0 __exceptionPreprocess + 176 1 libobjc.A.dylib 0x000000018b8c2b60 objc_exception_throw + 88 2 CoreFoundation 0x000000018bdfdce0 +[NSException exceptionWithName:reason:userInfo:] + 0 3 AppKit 0x000000019043d394 -[NSWindow(NSDisplayCycle) _postWindowNeedsUpdateConstraints] + 1788 4 AppKit 0x000000018f9f8c08 -[NSView _informContainerThatSubviewsNeedUpdateConstraints] + 64 5 AppKit 0x000000018f9f8b8c -[NSView setNeedsUpdateConstraints:] + 468 6 SwiftUI 0x00000001bc0e5110 $s7SwiftUI13NSHostingViewC14setNeedsUpdate33_32B6F54841135BB466A5C1362EB89D05LLyyF + 80 7 SwiftUI 0x00000001bc101f28 $s7SwiftUI13NSHostingViewC13requestUpdate5afterySd_tF + 616 Conditions that are important: accessing a publishable property inside the sheet .sheet() on a component that is wrapped in another (VStack is required in the example provided) being used inside NavigationSplitView Presents of @Environment(\.openURL. Doesn't have to be used, simply present on the view. struct ContentView: View { @Environment(\.openURL) private var open @State var who = "world" @State var shown = false var body: some View { NavigationSplitView(sidebar: { Text("Hello, world") }, detail: { VStack(spacing: 20) { Button("Kill me pls") { shown = true } .frame(width: 110, height: 110) .sheet(isPresented: $shown) { VStack { HStack() { Text("Hello, \(who)!") } } .presentationBackground(.thinMaterial) } } }) } }
Replies
2
Boosts
0
Views
164
Activity
Apr ’25
Printing NSTextStorage over multiple UITextView produces weird results
I would like to print a NSTextStorage on multiple pages and add annotations to the side margins corresponding to certain text ranges. For example, for all occurrences of # at the start of a line, the side margin should show an automatically increasing number. My idea was to create a NSLayoutManager and dynamically add NSTextContainer instances to it until all text is laid out. The layoutManager would then allow me to get the bounding rectangle of the interesting text ranges so that I can draw the corresponding numbers at the same height inside the side margin. This approach works well on macOS, but I'm having some issues on iOS. When running the code below in an iPad Simulator, I would expect that the print preview shows 3 pages, the first with the numbers 0-1, the second with the numbers 2-3, and the last one with the number 4. Instead the first page shows the number 4, the second one the numbers 2-4, and the last one the numbers 0-4. It's as if the pages are inverted, and each page shows the text starting at the correct location but always ending at the end of the complete text (and not the range assigned to the relative textContainer). I've created FB17026419. class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { let printController = UIPrintInteractionController.shared let printPageRenderer = PrintPageRenderer() printPageRenderer.pageSize = CGSize(width: 100, height: 100) printPageRenderer.textStorage = NSTextStorage(string: (0..<5).map({ "\($0)" }).joined(separator: "\n"), attributes: [.font: UIFont.systemFont(ofSize: 30)]) printController.printPageRenderer = printPageRenderer printController.present(animated: true) { _, _, error in if let error = error { print(error.localizedDescription) } } } } class PrintPageRenderer: UIPrintPageRenderer, NSLayoutManagerDelegate { var pageSize: CGSize! var textStorage: NSTextStorage! private let layoutManager = NSLayoutManager() private var textViews = [UITextView]() override var numberOfPages: Int { if !Thread.isMainThread { return DispatchQueue.main.sync { [self] in numberOfPages } } printFormatters = nil layoutManager.delegate = self textStorage.addLayoutManager(layoutManager) if textStorage.length > 0 { let glyphRange = layoutManager.glyphRange(forCharacterRange: NSRange(location: textStorage.length - 1, length: 0), actualCharacterRange: nil) layoutManager.textContainer(forGlyphAt: glyphRange.location, effectiveRange: nil) } var page = 0 for textView in textViews { let printFormatter = textView.viewPrintFormatter() addPrintFormatter(printFormatter, startingAtPageAt: page) page += printFormatter.pageCount } return page } func layoutManager(_ layoutManager: NSLayoutManager, didCompleteLayoutFor textContainer: NSTextContainer?, atEnd layoutFinishedFlag: Bool) { if textContainer == nil { addPage() } } private func addPage() { let textContainer = NSTextContainer(size: pageSize) layoutManager.addTextContainer(textContainer) let textView = UITextView(frame: CGRect(origin: .zero, size: pageSize), textContainer: textContainer) textViews.append(textView) } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
4
Boosts
0
Views
127
Activity
Apr ’25
Transforming RealityKit entities using gestures
In the section : Add transform logic to the main component There is the line : var state: GestureStateComponent = entity.gestureStateComponent ?? GestureStateComponent() When I try to add the same line. I have the error cannot find GestureStateComponent in scope. My imports : import SwiftUI import RealityKit import RealityKitContent An answer would be greatly appreciate it
Replies
2
Boosts
0
Views
78
Activity
Apr ’25
iOS17 UITextView inputView becomFirstResponder does not work
Simplely, when we set UITextView.inputView and then call becomeFirstResponder, but the custom inputView could not show expectedly just like before. We test this code in iOS17 and below, while only iOS17 does not work. And xcode console print these logs: Failed to retrieve snapshot. -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked: Unsupported action selector setShiftStatesNeededInDestination:autoShifted:shiftLocked:
Replies
49
Boosts
17
Views
37k
Activity
Apr ’25