Search results for

swiftui

16,632 results found

Post

Replies

Boosts

Views

Activity

Reply to Potential Structural Swift Concurrency Issue: unsafeForcedSync called from Swift Concurrent context
I've seen this error message too when running a very simple SwiftUI app (built using Xcode 26.0 (17A324)) on my device (iPhone 16 running iOS 26.0 (23A341)): Start the app Wait 10 seconds Send the app to the background. No other user interaction is necessary. The LLDB statement you provided does catch the location of the error message. But the stack trace is not helpful, as non of my code is involved. But what I've seen is that the error message is written to the console when the app is sent for the first time to the background. It doesn't appear anymore afterwards. The call stack I've captured is: #0 0x00000001a74e1280 in os_log () #1 0x00000001914d4218 in ___lldb_unnamed_symbol7481 () #2 0x000000018b2855c0 in ___lldb_unnamed_symbol14749 () #3 0x00000001914dc944 in ___lldb_unnamed_symbol7669 () #4 0x00000001914dce24 in ___lldb_unnamed_symbol7677 () #5 0x00000001de688520 in partial apply forwarder for closure #1 (Swift.UnsafeMutablePointer>) -> τ_0_0 in Observation.generateAccessList<τ_0_0&g
Sep ’25
SwiftUI Bug: Asset Catalog image for Regular Width Class not loaded
I've discovered what I think is a bug in SwiftUI unless I'm doing something obviously wrong. I have an Asset Catalogue configured with an image that has variants for Any width size class and Regular width size class. When the Image is loaded with the following code: struct ContentView: View { var body: some View { VStack { Image(icon) } .padding() } } when running on an iPad you would expect the image for the Regular width size class to be displayed. However, it seems that it is only ever the image for the Any width size class that is loaded. Is this a known issue with Asset Catalogs and SwiftUI?
1
0
136
Sep ’25
Template Project Entity Overlapping and Sticking Issues
Hello, There are three issues I am running into with a default template project + additional minimal code changes: the Sphere_Left entity always overlaps the Sphere_Right entity. when I release the Sphere_Left entity, it does not remain sticking to the Sphere_Right entity when I release the Sphere_Left entity, it distances itself from the Sphere_Right entity When I manipulate the Sphere_Right entity, these above 3 issues do not occur: I get a correct and expected behavior. These issues are simple to replicate: Create a new project in XCode Choose visionOS -> App, then click Next Name your project, and leave all other options as defaults: Initial Scene: Window, Immersive Space Renderer: RealityKit, Immersive Space: Mixed, then click Next Save you project anywhere... Replace the entire ImmersiveView.swift file with the below code. Run. Try to manipulate the left sphere, you should get the same issues I mentioned above If you restart the project, and manipulate only the right sphere, you should get the correc
8
0
402
Sep ’25
Core Data + CKSyncEngine with Swift 6 — concurrency, Sendable, and best practices validation
Hi everyone, I’ve been working on migrating my app (SwimTimes, which helps swimmers track their times) to use Core Data + CKSyncEngine with Swift 6. After many iterations, forum searches, and experimentation, I’ve created a focused sample project that demonstrates the architecture I’m using. The good news: 👉 I believe the crashes I was experiencing are now solved, and the sync behavior is working correctly. 👉 The demo project compiles and runs cleanly with Swift 6. However, before adopting this as the final architecture, I’d like to ask the community (and hopefully Apple engineers) to validate a few critical points, especially regarding Swift 6 concurrency and Core Data contexts. Architecture Overview Persistence layer: Persistence.swift sets up the Core Data stack with a main viewContext and a background context for CKSyncEngine. Repositories: All Core Data access is abstracted into repository classes (UsersRepository, SwimTimesRepository), with async/await methods. SyncEngine: Wraps CKSyncEngine, handles
3
0
449
Sep ’25
iOS 26 SwiftData crash does not happen in iOS 16
I have a simple app that makes an HTTPS call to gather some JSON which I then parse and add to my SwiftData database. The app then uses a simple @Query in a view to get the data into a list. on iOS 16 this works fine. No problems. But the same code on iOS 26 (targeting iOS 18.5) crashes after about 15 seconds of idle time after the list is populated. The error message is: Could not cast value of type '__NSCFNumber' (0x1f31ee568) to 'NSString' (0x1f31ec718). and occurs when trying to access ANY property of the list. I have a stripped down version of the app that shows the crash available. To replicate the issue: open the project in Xcode 26 target any iOS 26 device or simulator compile and run the project. after the list is displayed, wait about 15 seconds and the app crashes. It is also of note that if you try to run the app again, it will crash immediately, unless you delete the app from the device. Any help on this would be appreciated. Feedback number FB20295815 includes .zip file Below is the basic code (
4
0
222
Sep ’25
Reply to Sufficient mac for Xcode web app development project
If you use an M1 MacBook Air with 8 GB of memory, you may not be able to open multiple Xcode projects. I had one 2 and a half years ago at work. It often hung up. Also, depending on how much you write code, Xcode projects can quickly fill up your SSD. My M2 Mac mini has 512 GB space with an external HD taken from an old iMac machine. Each week, I create a few dozen Xcode projects in SwiftUI and lose several GB to them. So I end up deleting old data folders in DrivedData. As you probably, you cannot increase memory or swap SDDs with machines with Apple-made chips.
Sep ’25
macOS 26 toolbar has wrong tint color sometimes in Dark Appearance
I have a SwiftUI Mac Catalyst app. I create a toolbar like this NavigationSplitView(columnVisibility: $sceneModel.columnVisibility, preferredCompactColumn: $preferredColumn) { sidebarView() } detail: { contentView() .toolbar { ToolbarItemGroup(placement: .topBarTrailing) { HStack { Button { sceneModel.onMaps(sender: self) } label: { Image(systemName: map) .font(.title2) } Button { sceneModel.onSearch(sender: self) } label: { Image(systemName: magnifyingglass) .font(.title2) } ... } } } } When my Mac Appearance is set to dark mode and the content under the toolbar is dark the toolbar looks good like this. But then if I have light content under the toolbar, the glass effect changes to light, but the tint on the icons stays white instead of changing to black and it is hard to see the icon. It looks like this. When I set the Appearance on my Mac to light, then the toolbar works just fine on both dark and light colored backgrounds. Does anyone know how I can fix this when the appearance is Dark?
8
0
249
Sep ’25
Reply to Avoid using a segmented control in a toolbar
I think what they say is that you are advised to use TabView (in SwiftUI) if you are going to switch the entire content of the view. The Phone app seems to use a segmented control. (But who knows!?) Yet, it's used to filter the list content. Whatever it is isn't changing the entire content of the view.
Topic: Design SubTopic: General Tags:
Sep ’25
How To Position Controls With SwiftUI
I am coming from C#, where Forms and Controls are placed similar to Swift Storyboards. I have been trying to learn Storyboards, but keep running across tutorials regarding SwiftUI, and Storyboard examples are few. So the question becomes, how do I position controls on a Form using SwiftUI? See the example below. I have run across many videos that use either horizontal or vertical positioning of controls, but these examples are usually very simple, with items occupying only the center portion of the screen. I get stuck on examples that are more complicated. The example below only shows the controls for the upper part of a Form, with some type of textbox (Viewform) below making up the rest of the Form. How does one make more complicated placement of controls with SwiftUI?
10
0
415
Sep ’25
SwiftUI TextField corrupts selection when inserting utf16
The example code below shows what I am trying to achieve: When the user types a '*', it should be replaced with a '×'. It looks like it works, but the cursor position is corrupted, even though it looks OK, and the diagnostics that is printed below shows a valid index. If you type 12*34 you get 12×43 because the cursor is inserting before the shown cursor instead of after. How can I fix this? struct ContentView: View { @State private var input: String = @State private var selection: TextSelection? = nil var body: some View { VStack { TextField(Type 12*34, text: $input, selection: $selection) .onKeyPress(action: {keyPress in handleKeyPress(keyPress) }) Text(Selection: (selectionAsString())) }.padding() } func handleKeyPress(_ keyPress: KeyPress) -> KeyPress.Result { if (keyPress.key.character == *) { insertAtCursor(text: ×) moveCursor(offset: 1) return KeyPress.Result.handled } return KeyPress.Result.ignored } func moveCursor(offset: Int) { guard let selection else { return } if case let .selection(range) =
Topic: UI Frameworks SubTopic: SwiftUI
7
0
156
Sep ’25
Reply to How To Position Controls With SwiftUI
Hi Ptit-Xav, I placed the controls in the same manner as Claude31 recommended. If there is a better placement methods, please specify I don't know what you mean by placement constraint My view above is what I thought was a logical subview Regarding ZStack, I thought this was used to control depth of controls, such as various picture objects on top of each other. Don't know what you mean by global view, or what an overlay is I have spent about one month attempting to find comprehensive documentation on SwiftUI and its controls and how to place them, but have come up short. Even Rust has better documentation when it comes to the types of controls available (think FLTK or Iced), what they look like, and how to use them. 99% of the designs are a single vertical column. I have several SwiftUI books, and they cover a lot of material, but answering specific questions about how to place controls on a Form, epecially when the design is more complex, is seemingly hard to come by. Sorry for all the que
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’25
iOS 26 @FocusState Doesn't Work If TextField Is In Toolbar
When I add a TextField with @FocusState to a toolbar, I noticed that setting focus = false doesn't cause the form to lose focus If I move the TextField out of the toolbar setting focus = false works fine. How can I unfocus the text field when the cancel button is tapped? Minimal example tested on Xcode Version 26.0 beta 6 (17A5305f): import SwiftUI struct ContentView: View { @State private var text: String = @FocusState private var focus: Bool var body: some View { NavigationStack { List { Text(Test List) } .toolbar { ToolbarItem(placement: .bottomBar) { TextField(Test, text: $text) .padding(.horizontal) .focused($focus) } ToolbarItem(placement: .bottomBar) { Button(role: .cancel) { focus = false // THIS DOESN'T WORK! } } } } } } #Preview { ContentView() }```
1
0
269
Sep ’25
`onTapGesture` not triggered on `Map` views
When building with iOS 26 SDK beta 5 (23A5308f), onTapGesture is no longer being triggered on Map views. This appears to be a regression in beta 5 specifically, as this issue was not present in beta 4. How to reproduce Code The following code demonstrates the issue, as seen in the videos below. import MapKit import SwiftUI struct ContentView: View { @State private var location = CGPoint.zero var body: some View { Map() .onTapGesture { location in self.location = location } .safeAreaInset(edge: .bottom) { VStack(alignment: .center) { Text(iOS (UIDevice.current.systemVersion)) .font(.largeTitle) Text(Tapped Location) Text((location.x), (location.y)) } .frame(maxWidth: .infinity, alignment: .center) .background(.background) } } } Demo The gifs below show the behavior in iOS 18.5 (in which the tap gestures are recognized and tapped coordinate is displayed in the safe area inset) and iOS 26 beta 5 (in which the tap gestures have no effect): iOS 18 iOS 26 Next steps? Is there a recommended workaround for t
19
0
1.3k
Sep ’25