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

WebView sits under the notch
Such a simple piece of code: import SwiftUI import WebKit struct ContentView: View { var body: some View { WebView(url: URL(string: "https://www.apple.com")) } } When I run this, the web content shows under the top notch’s safe area, and buttons inside that region aren’t tappable. I tried a bunch of things and the only “fix” that seems to work is .padding(.top, 1), but that leaves a noticeable white strip in non-portrait orientations. What’s the proper way to solve this? Safari handles the safe area correctly and doesn’t render content there.
1
1
81
21h
Switfui: change color in 'menu'
in swiftui how can I change the text color when use "menu"? I mean I need that each text in pippo will be .red color as you can see in the code, but .foregroundColor(.red) do not works thanks var pippo = ["AAA","BBB","CCC", "DDD"] var body: some View { Menu { ForEach(pippo, id: \.self) { item in Button { //categoriaSelezionata = categoria } label: { Text(item) .foregroundColor(.red) } } } label: { HStack { Text("Select Theme") .multilineTextAlignment(.center) Image(systemName: "chevron.down") .foregroundColor(.gray) } .frame(maxWidth: .infinity) .padding(6) } Menu { ForEach(pippo, id: \.self) { item in Button(item) { // azione } .foregroundColor(.red) } } label: { HStack { Text("Select Theme") Image(systemName: "chevron.down") .foregroundColor(.gray) } .frame(maxWidth: .infinity) .padding(6) } .menuStyle(BorderlessButtonMenuStyle()) // Prova diversi stili .menuIndicator(.hidden) // Nasconde l'indicatore di default }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
77
21h
iOS 26.1 button with role .confirm delay
The same code that I have, runs fine on iOS 26.0, but on iOS 26.1, there's a delay in the Button with role .confirm to be shown properly and tinted. Shown in the screen recording here -> https://imgur.com/a/uALuW50 This is my code that shows slightly different button in iOS 18 vs iOS26. var body: some View { if #available(iOS 26.0, *) { Button("Save", systemImage: "checkmark", role: .confirm) { action() }.labelStyle(.iconOnly) } else { Button("Save") { action() } } }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
206
22h
NSScrollView two finger drag being interrupted
I have a fairly robust MacOS application that has an NSScrollView that contains a canvas with various subviews (including web views and text views that contain scroll views), and a couple of peer views that track items in the scroll view (eg: screen space controls). Some of these views interrupt two finger scrolling. Every scroll view, and one of the peer views (essentially a stack view with buttons in it). I have written an additional bare bones application which does roughly the same thing, and my bare bones application works perfectly: Start two-finger dragging, scroll any of these other things under the cursor, I can continue to drag (and start dragging in any of those, and they drag without interfering with the parent scroll view). I have tried everything to recreate the interruption, including drag gestures attached to these various ancillary views, and I cannot figure out why dragging some of these views under the cursor interrupts two finger drag in our application, but not in my testbed. Does anyone have suggestions for how to debug this? I can see that there is a gesture recognizer in the NSScrollView hierarchy, but I don't see it in any of my gesture recognizer handling. I have breakpoints on every variation of hit testing and mouse motion, and none of them are getting hit in unexpected ways. I'm at my wit's end. Thanks.
Topic: UI Frameworks SubTopic: AppKit Tags:
3
1
616
23h
Correctly initializing observable classes in modern SwiftUI
I have two @Observable manager classes, which share a reference to a third class. I initialize this setup using a custom init in my App struct, like so: @main struct MyApp: App { private let managerA: ManagerA private let managerB: ManagerB init() { let managerC = ManagerC() self.managerA = ManagerA(managerC: managerC) self.managerB = ManagerB(managerC: managerC) } var body: some Scene { WindowGroup { ContentView() .environment(managerA) .environment(managerB) } } } I've been using this pattern for some time and it has been working fine. However, I just today discovered that @Observable objects are supposed to be initialized as @State vars, as shown in Apple's documentation here. This means I shoud be doing the following: @main struct MyApp: App { @State private var managerA: ManagerA @State private var managerB: ManagerB init() { let managerC = ManagerC() self.managerA = ManagerA(managerC: managerC) self.managerB = ManagerB(managerC: managerC) } var body: some Scene { WindowGroup { ContentView() .environment(managerA) .environment(managerB) } } } I've also seen some examples where the @State vars are initialized manually like this: @main struct MyApp: App { @State private var managerA: ManagerA @State private var managerB: ManagerB init() { let managerC = ManagerC() let managerA = ManagerA(managerC: managerC) let managerB = ManagerB(managerC: managerC) self._managerA = State(initialValue: managerA) self._managerB = State(initialValue: managerB) } var body: some Scene { WindowGroup { ContentView() .environment(managerA) .environment(managerB) } } } ChatGPT tells me the third approach is the correct one, but I don't understand why and ChatGPT can't produce a convincing explanation. The compiler doesn't produce any errors or warnings under each approach, and as far as I can tell, they all behave identically with no discernible difference in performance. Does it matter which pattern I use? Is there a "correct" way?
2
0
44
23h
iPadOS 26.1: new issue with traitCollection when changing dark mode
Since iPadOS 26.1 I notice a new annoying bug when changing the dark mode option of the system. The appearance of the UI changes, but no longer for view controllers which are presented as Popover. For these view controllers the method "traitCollectionDidChange()" is still called (though sometimes with a very large delay), but checking the traitCollection property of the view controller in there does no longer return the correct appearance (which is probably why the visual appearance of the popover doesn't change anymore). So if the dark mode was just switched on, traitCollectionDidChange() is called, but the "traitCollection.userInterfaceStyle" property still tells me that the system is in normal mode. More concrete, traitCollection.userInterfaceStyle seems to be set correctly only(!) when opening the popover, and while the popover is open, it is never updated anymore when the dark mode changes. This is also visible in the standard Apps of the iPad, like the Apple Maps App: just tap on the "map" icon at the top right to open the "Map mode" view. While the view is open, change the dark mode. All of the Maps App will change its appearance, with the exception of this "Map mode" view. Does anyone know an easy workaround? Or do I really need to manually change the colors for all popup view controllers whenever the dark mode changes? Using dynamic UIColors won't help, because these rely on the "userInterfaceStyle" property, and this is no longer correct. Bugreport: FB20928471
3
1
226
1d
popoverTip prevents tap recognition
I am noticing an issue that when .popoverTip() is presented, any tap gesture will only dismiss the tip and will not be passed down. This means that if tip is applied to a button, tapping the button will only dismiss the tip but will not trigger the action. Which logically breaks user expectation and defeats the whole point of a popover tip, as user will need to tap twice on the button to activate intended functionality. Button("Settings", systemImage: "gear") { // Will not trigger until tip is dismissed and button is tapped again. showSettings.toggle() } .popoverTip(SettingsTip())
3
0
156
1d
`NewDocumentButton(contentType:)` gives "Content serialization failed, document won't be saved."
I'm working on an iOS document-based app. It uses ReferenceFileDocument and custom creation of documents via DocumentGroupLaunchScene + NewDocumentButton. It works fine when I use the plain NewDocumentButton("Whatever") (without any more arguments), but when I want to perform additional setup via preapreDocumentURL or even just add a contentType it gives such output in the console when I hit it: Content serialization failed, document won't be saved. UTType.replayable is correctly wired up in the plist. It looks like a bug in the SDK, but maybe there is a chance that I'm doing something wrong? Here's a code: import SwiftUI import UniformTypeIdentifiers import Combine @main struct MyApp: App { var body: some Scene { DocumentGroup { Document() } editor: { documentConfiguration in EmptyView() } DocumentGroupLaunchScene("Yoyo") { NewDocumentButton(contentType: .replayable) { return URL(string: "whatever, it doesnt even go there...")! } } } } final class Document: ReferenceFileDocument { static var readableContentTypes: [UTType] { [.replayable] } @Published var x = 0 init() {} init(configuration: ReadConfiguration) throws {} func snapshot(contentType: UTType) throws -> Data { Data() } func fileWrapper(snapshot: Data, configuration: WriteConfiguration) throws -> FileWrapper { .init(regularFileWithContents: snapshot) } } extension UTType { static var replayable: UTType { UTType(exportedAs: "com.whatever.yo") } }
2
0
54
1d
refreshable modifier causes misaligned button tap targets in ScrollView
I have a ScrollView with several Buttons and a .refreshable modifier. As soon as I pull to refresh and the refresh indicator appears, the tap targets no longer match the visible button positions. For example, tapping button A triggers button B’s action, as if the hit-testing region didn’t move along with the content. This only happens while the refresh indicator is shown. Before pulling to refresh, everything is correct and afterwards as well. Tested on iOS 18 and 26 (Xcode 16.4, Xcode 26). Here is a minimal reproducible example: import SwiftUI struct ContentView: View { var body: some View { ScrollView { VStack { Button("Button A") { print("A") } .buttonStyle(.borderedProminent) Button("Button B") { print("B") } .buttonStyle(.borderedProminent) Button("Button C") { print("C") } .buttonStyle(.borderedProminent) Button("Button D") { print("D") } .buttonStyle(.borderedProminent) Button("Button E") { print("E") } .buttonStyle(.borderedProminent) } .frame(maxWidth: .infinity) } .refreshable { try? await Task.sleep(for: .seconds(60)) } } }
1
0
57
1d
Reliable Alternative for Google Sign-In with AWS Cognito on iOS (React Native)
I’m developing a React Native application using AWS Cognito Hosted UI with Google Sign-In for authentication.My setup uses: React Native: 0.76.9 Library: react-native-app-auth version 8.0.3 Xcode Minimum Deployment Target: 13.4 The same implementation works perfectly on Android, but on iOS it behaves inconsistently. Here’s the issue: Login flow completes successfully. However, access tokens and ID tokens are often null or malformed on iOS. This results in 401 Invalid Token errors when calling backend APIs. I’ve also tried using react-native-inappbrowser-reborn, but the issue persists.I’m currently using both the client ID and reverse client ID correctly as callback URLs in Cognito’s configuration". So my questions are: "Is it better to continue using react-native-app-auth and @react-native-google-signin/google-signin with improved configuration for iOS? Or is there a more reliable approach/library for handling Cognito authentication and token management on iOS (especially for Hosted UI with Google Sign-In)? Looking forward to any suggestions or best practices from those who’ve implemented Cognito + Google Sign-In on iOS using React Native.If you’ve found a stable setup for managing tokens and callbacks on iOS, please share your approach". Thank you!
1
0
20
1d
WatchOS version lower than deployment target in Xcode 26
Description: I’m encountering an issue where the Apple Watch’s watchOS version is lower than the deployment target specified in my Xcode project. For example, my Watch device is running watchOS 10.6, but my app’s deployment target is set to watchOS 9.6 or 10.6, and Xcode shows an error stating: Error: “watchOS version doesn’t match the app’s deployment target.” Could someone clarify how to properly handle this version mismatch? Environment: Xcode 26 iPhone: iOS 18 Apple Watch: watchOS 10.6 Any guidance or best practices would be appreciated.
3
1
131
1d
UITrackingElementWindowController related crash on iPadOS26.1
I have following code and made it invoke every time when a UIViewController presents another UIViewController through method swizzling. When I try to access the Password management app while input password, these code will be invoked and the presenting VC is instance of UITrackingElementWindowController. It will crash [presentingVC beginAppearanceTransition:NO animated:NO]; [presentingVC endAppearanceTransition];
1
0
26
1d
Recommended approach for migrating to modern (iOS 16+) navigation
Hello all, my team and I are looking for some advice on updating our app from using NavigationView and NavigationLink to NavigationStack and .navigationDestination now that NavigationView is deprecated. A little background about our situation, our app is a mix of SwiftUI views and UIKit view controllers. We are slowly migrating towards primarily SwiftUI and we are at the point now where our main app entry point is SwiftUI. UIKit is now mainly just used for some legacy screens inside the app, but majority of our navigation is using SwiftUI with NavigationLinks. I have spent a couple weeks on trying to migrate to using NavigationStack + .navigationDestination, but every time I do I keep running into issues. From what I understand, there seems to be two competing approaches for modern navigation. Those two approaches are... Having a more global navigationDestination modifier defined at the root of each tab that essentially supports navigating to all pages. I have seen this referred to as a 'router'. Applying a navigationDestination modifier on each page that navigates somewhere. This seems to be more 1-to-1 port of how we are currently using NavigationLink. However, I tried implementing both of these solutions in our app and with both of them I ran into countless issues which made me second guess the solution I was currently implementing in favor of the other. This has led to where I am now, where I am really unsure what the recommended approach is. I would love to hear from you all, what you have had the most success with. I am interested to hear what approach you chose, why you chose that, and then also some downsides to the approach you chose. Thanks in advance.
Topic: UI Frameworks SubTopic: SwiftUI
2
0
43
1d
Where to find appearance icons from System Settings ?
Hello. I am searching the appearance icons from System Settings to select Dark Mode, Light Mode or Auto. I am searching for the path (including file name) in Finder so that my app can use it no matter the macOS version. I will gladly include a screenshot of what I am looking for. (sorry for the french) I hope I will find an answer that will work out, as this is a personal project that I am most interested in to work for
Topic: UI Frameworks SubTopic: General
0
0
19
1d
Crash on _UIButtonBarItemLayout _updateItemView
With iOS 26.1 and beta 26.2, there is a crash seen for _UIButtonBarItemLayout update. Has anyone experienced this crash or has any information on this Thread 0 name: Thread 0 Crashed: 0 libobjc.A.dylib 0x000000019daa144c objc_retain + 16 1 UIKitCore 0x00000001a680b184 -[_UIButtonBarItemLayout _updateItemView] + 360 2 UIKitCore 0x00000001a6d5ddcc -[_UIButtonBarItemLayout minimumLayoutWidthGivenMinimumSpaceWidth:] + 28 3 UIKitCore 0x00000001a6d5eeec -[_UIButtonBarItemGroupLayout recalculateLayoutWidthsGivenItemSpaceWidth:] + 304 4 UIKitCore 0x00000001a6d4ca28 -[_UIButtonBar _widthInfoForLayout:] + 188 5 UIKitCore 0x00000001a68093b4 -[_UIButtonBar _layoutBar] + 108 6 UIKitCore 0x00000001a6809328 __42-[_UIButtonBarStackView updateConstraints]_block_invoke + 44 7 UIKitCore 0x00000001a7dbea8c +[UIView(Animation) performWithoutAnimation:] + 76 8 UIKitCore 0x00000001a68092d0 -[_UIButtonBarStackView updateConstraints] + 112 9 UIKitCore 0x00000001a64707e8 -[UIView(AdditionalLayoutSupport) _previousFittingSizeInfo] + 784 10 UIKitCore 0x00000001a6470508 -[UIView(AdditionalLayoutSupport) _previousFittingSizeInfo] + 48
Topic: UI Frameworks SubTopic: UIKit
1
1
83
1d
UIDocumentPickerViewController does not allow picking folders on connected servers on iOS26
Hey there, I have an app that allows picking any folder via UIDocumentPickerViewController. Up until iOS18 users were able to pick folders from connected servers (servers connected in the Files app) as well. On iOS26, the picker allows for browsing into the connected servers, but the Select button is greyed out and does nothing when tapped. Is this a known issue? This breaks the whole premise of my file syncronization application.
5
0
166
1d
[CBXpcConnection _sendBarrier] iOS26 App Crash or ANR
the app crashes about 10 seconds after it goes into the background libsystem_kernel.dylib semaphore_wait_trap 100% 45 dyld start + 7116 [0x1825fa000] 100% 44 xxxx main + 76 (main.m:38) [0x104c14000] 100% 43 UIKitCore UIApplicationMain + 336 [0x18ae57000] 100% 42 UIKitCore -[UIApplication _run] + 792 [0x18ae57000] 100% 41 GraphicsServices GSEventRunModal + 120 [0x224975000] 100% 40 CoreFoundation _CFRunLoopRunSpecificWithOptions + 532 [0x185569000] 100% 39 CoreFoundation __CFRunLoopRun + 820 [0x185569000] 100% 38 CoreFoundation __CFRunLoopDoSources0 + 232 [0x185569000] 100% 37 CoreFoundation __CFRunLoopDoSource0 + 172 [0x185569000] 100% 36 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 [0x185569000] 100% 35 BoardServices BSServiceMainRunLoopSourceHandler + 224 [0x19c8b0000] 100% 34 BoardServices __BSSERVICEMAINRUNLOOPQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52 [0x19c8b0000] 100% 33 libdispatch.dylib _dispatch_block_invoke_direct + 284 [0x1bcf40000] 100% 32 libdispatch.dylib _dispatch_client_callout + 16 [0x1bcf40000] 100% 31 FrontBoardServices -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 168 [0x1a4d45000] 100% 30 FrontBoardServices __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2 + 96 [0x1a4d45000] 100% 29 FrontBoardServices __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2.cold.1 + 352 [0x1a4d45000] 100% 28 FrontBoardServices -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:] + 708 [0x1a4d45000] 100% 27 FrontBoardServices -[FBSScene _callOutQueue_maybeCoalesceClientSettingsUpdates:] + 128 [0x1a4d45000] 100% 26 FrontBoardServices __76-[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.129 + 380 [0x1a4d45000] 100% 25 UIKitCore -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 336 [0x18ae57000] 100% 24 UIKitCore -[UIScene scene:didUpdateWithDiff:transitionContext:completion:] + 244 [0x18ae57000] 100% 23 UIKitCore -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:] + 208 [0x18ae57000] 100% 22 UIKitCore __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.218 + 616 [0x18ae57000] 100% 21 UIKitCore -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:] + 316 [0x18ae57000] 100% 20 UIKitCore _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion + 224 [0x18ae57000] 100% 19 UIKitCore +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:] + 736 [0x18ae57000] 100% 18 UIKitCore __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke + 148 [0x18ae57000] 100% 17 UIKitCore -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:] + 244 [0x18ae57000] 100% 16 UIKitCore -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:] + 608 [0x18ae57000] 100% 15 UIKitCore -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:] + 212 [0x18ae57000] 100% 14 UIKitCore __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke + 252 [0x18ae57000] 100% 13 UIKitCore _UIScenePerformActionsWithLifecycleActionMask + 112 [0x18ae57000] 100% 12 UIKitCore __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2 + 512 [0x18ae57000] 100% 11 UIKitCore -[UIApplication _applicationDidEnterBackground] + 136 [0x18ae57000] 100% 10 UIKitCore +[UIViewController _performWithoutDeferringTransitionsAllowingAnimation:actions:] + 140 [0x18ae57000] 100% 9 UIKitCore __47-[UIApplication _applicationDidEnterBackground]_block_invoke + 256 [0x18ae57000] 100% 8 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] + 92 [0x182c3d000] 100% 7 CoreFoundation _CFXNotificationPost + 736 [0x185569000] 100% 6 CoreFoundation _CFXRegistrationPost + 436 [0x185569000] 100% 5 CoreFoundation ___CFXRegistrationPost_block_invoke + 92 [0x185569000] 100% 4 CoreFoundation __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148 [0x185569000] 100% 3 CoreBluetooth -[CBXpcConnection _sendBarrier] + 188 [0x1c2254000] 100% 2 libdispatch.dylib _dispatch_semaphore_wait_slow + 132 [0x1bcf40000] 100% 1 libdispatch.dylib _dispatch_sema4_wait + 28 [0x1bcf40000] 100% 0 libsystem_kernel.dylib semaphore_wait_trap + 8 [0x22d5b6000]
0
0
48
1d
iOS26+, MKMapview crash
I have a UIViewController that uses MKMapview to display the motion history trajectory. Repeatedly entering and exiting UIViewController will cause a crash, and the crash stack is as follows: Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x000000014bfc0fc8 Exception Codes: 0x0000000000000001, 0x000000014bfc0fc8 VM Region Info: 0x14bfc0fc8 is not in any region. Bytes after previous region: 217033 Bytes before following region: 61496 REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL VM_ALLOCATE 14bf88000-14bf8c000 [ 16K] rw-/rwx SM=PRV ---> GAP OF 0x44000 BYTES VM_ALLOCATE 14bfd0000-14bfd4000 [ 16K] rw-/rwx SM=PRV Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [1881] Triggered by Thread: 8 Thread 8 name: Dispatch queue: com.apple.root.background-qos Thread 8 Crashed: 0 CoreFoundation 0x19e36ac40 CFRelease + 44 1 VectorKit 0x1ce16af6c md::TileGroupNotificationManager::~TileGroupNotificationManager() + 132 2 VectorKit 0x1cd6f7178 <deduplicated_symbol> + 76 3 VectorKit 0x1cdba8d74 -[VKSharedResources .cxx_destruct] + 32 4 libobjc.A.dylib 0x19b3321f8 object_cxxDestructFromClass(objc_object*, objc_class*) + 116 5 libobjc.A.dylib 0x19b32df20 objc_destructInstance_nonnull_realized(objc_object*) + 76 6 libobjc.A.dylib 0x19b32d4a4 _objc_rootDealloc + 72 7 VectorKit 0x1cdba93fc -[VKSharedResources dealloc] + 476 8 VectorKit 0x1cdafa3fc -[VKSharedResourcesManager _removeResourceUser] + 68 9 VectorKit 0x1cdafa380 +[VKSharedResourcesManager removeResourceUser] + 44 10 VectorKit 0x1cdafa2fc __37-[VKIconManager _internalIconManager]_block_invoke + 168 11 libdispatch.dylib 0x1d645b7ec _dispatch_client_callout + 16 12 libdispatch.dylib 0x1d6446664 _dispatch_continuation_pop + 596 13 libdispatch.dylib 0x1d6459528 _dispatch_source_latch_and_call + 396 14 libdispatch.dylib 0x1d64581fc _dispatch_source_invoke + 844 15 libdispatch.dylib 0x1d6453f48 _dispatch_root_queue_drain + 364 16 libdispatch.dylib 0x1d64546fc _dispatch_worker_thread2 + 180 17 libsystem_pthread.dylib 0x1f9b7e37c _pthread_wqthread + 232 18 libsystem_pthread.dylib 0x1f9b7d8c0 start_wqthread + 8 I have checked the code and did not find any issues. I have also tested on iOS 15, 16, and 18 without any issues. Could this be an error in the iOS 26 system? Have you ever met any friends? I hope to receive an answer. Thank you.
3
0
113
1d
How to correctly fetch data using SwiftData
Hi there! I'm making an app that stores data for the user's profile in SwiftData. I was originally going to use UserDefaults but I thought SwiftData could save Images natively but this is not true so I really could switch back to UserDefaults and save images as Data but I'd like to try to get this to work first. So essentially I have textfields and I save the values of them through a class allProfileData. Here's the code for that: import SwiftData import SwiftUI @Model class allProfileData { var profileImageData: Data? var email: String var bio: String var username: String var profileImage: Image { if let data = profileImageData, let uiImage = UIImage(data: data) { return Image(uiImage: uiImage) } else { return Image("DefaultProfile") } } init(email:String, profileImageData: Data?, bio: String, username:String) { self.profileImageData = profileImageData self.email = email self.bio = bio self.username = username } } To save this I create a new class (I think, I'm new) and save it through ModelContext import SwiftUI import SwiftData struct CreateAccountView: View { @Query var profiledata: [allProfileData] @Environment(\.modelContext) private var modelContext let newData = allProfileData(email: "", profileImageData: nil, bio: "", username: "") var body: some View { Button("Button") { newData.email = email modelContext.insert(newData) try? modelContext.save() print(newData.email) } } } To fetch the data, I originally thought that @Query would fetch that data but I saw that it fetches it asynchronously so I attempted to manually fetch it, but they both fetched nothing import SwiftData import SwiftUI @Query var profiledata: [allProfileData] @Environment(\.modelContext) private var modelContext let fetchRequest = FetchDescriptor<allProfileData>() let fetchedData = try? modelContext.fetch(fetchRequest) print("Fetched count: \(fetchedData?.count ?? 0)") if let imageData = profiledata.first?.profileImageData, let uiImage = UIImage(data: imageData) { profileImage = Image(uiImage: uiImage) } else { profileImage = Image("DefaultProfile") } No errors. Thanks in advance
7
0
222
1d