Search results for

swiftui

16,584 results found

Post

Replies

Boosts

Views

Activity

Drawing a PaperMarkup synchronously
The PaperMarkup class in PaperKit allows for an asynchronous function called .draw(in:, frame:) that we should call as: await paperMarkup.draw(in: context.cgContext, frame: rect) In PencilKit the PKDrawing that we can get from a PKCanvasView allows for .image(from: ,scale:) to be called synchronously. This allows me to easily render into a PKDrawing as a UIImage or a SwiftUI Image to, for example, render a thumbnail on screen. When trying to incorporate PaperKit in my project I noticed that I often need the drawing to be rendered synchronously (like I would with PKDrawing) but I can't find the way to accomplish this within PaperKit's current functionality. Is there any way to call .draw(...) in PaperKit synchronously? Feedback: FB20993683
2
0
104
Nov ’25
Reply to visionOS 3d interactions like the native keyboard when no longer observed in passthrough
Hi @VaiStardom I can confirm SpatialTapGesture doesn't consistently register direct input (trigger callbacks) on entities outside a person's field of view. However, you can use hand tracking to create a custom gesture that works on all entities, regardless of their position, as long as visionOS can track the person's hands. This approach only works within an ImmersiveSpace and requires adding an NSHandsTrackingUsageDescription entry to your app's Info.plist that explains why your app needs hand tracking access. The code snippet below demonstrates this technique by playing a sound when a person taps a cube, even when it's outside their field of view. import RealityKit import SwiftUI import AudioToolbox struct ImmersiveView: View { @State var spatialTrackingSession = SpatialTrackingSession() @State var collisionEventSubscription: EventSubscription? var body: some View { RealityView { content in let cube = ModelEntity( mesh: .generateBox(size: 0.1), materials: [SimpleMaterial(color: .green, isMetallic:
Topic: Spatial Computing SubTopic: ARKit Tags:
Nov ’25
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
2
0
76
Nov ’25
Reply to Recommended approach for migrating to modern (iOS 16+) navigation
A good staring point would be to review the following resources: Understanding the navigation stack Migrating to new navigation types WWDC22 session 10054: The SwiftUI cookbook for navigation. Without being prescriptive, your app’s navigation structure would depend on your app’s structure and the various functionalities it supports, such as state restoration, deep linking etc.
Topic: UI Frameworks SubTopic: SwiftUI
Nov ’25
Cannot Preview in this file. Simulator was shutdown during an update.
Hello, I am facing a recurring issue with Xcode iOS simulator (preview). I want to preview a SwiftUI for iOS in Xcode, but the Simulator app fails to boot up. I receive the following error in Xcode: Cannot Preview in this file. Simulator was shutdown during an update. I have tried the following: Completely uninstalling XCode and deleting all developer data, then reinstalling everthing again. Shutdown and restart Deleting all developer data, deleting XCode cache Reinstalling iOS Simulator runtimes and reconfiguration of simulators. Tested using different simulator and runtime versions. xcrun simctl --set previews delete al My reported issues: FB20987522 FB20485454 Thank you Best regards, Jens
3
0
133
Nov ’25
Cannot Preview in this file. Simulator was shutdown during an update.
Hello, I am facing a recurring issue with Xcode iOS simulator (preview). I want to preview a SwiftUI for iOS in Xcode, but the Simulator app fails to boot up. I receive the follow error in Xcode: Cannot Preview in this file. Simulator was shutdown during an update. I have tried the following: Uninstall Xcode and reinstall it again Deleting all developer data Deleting Xcode cache Reinstalling iOS Simulator runtimes and reconfiguration of simulators. Tested using different simulator and runtime versions. xcrun simctl --set previews delete al I reported the issue: FB20485454 FB20987522 Thank you. Best regards, Jens
0
0
73
Nov ’25
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 ref
Topic: UI Frameworks SubTopic: SwiftUI
2
0
70
Nov ’25
`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 readableConte
2
0
86
Nov ’25
Reply to Getting a basic URL Filter to work
AFAICT FB19582905 is with the right folks and on track to a resolution. I don’t have any info to share beyond that. FB14888965 is a SwiftUI thing, and thus far outside of my area of expertise. If you’d like to explore your options in that space, I recommend that you start a new thread over in UI Frameworks > SwiftUI. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = eskimo + 1 + @ + apple.com
Nov ’25
Reply to SwifUI Performance With Rapid UI Updates
In your case, you're probably re-evaluating the whole ContentView body 30 times per second, which includes laying out your stacks. I'd recommend using the SwiftUI instrument in Instruments 26 to see how many times your views are being updated. There's a WWDC talk from this year about the SwiftUI instrument that I'd highly recommend, and also, if you check the Apple Developer channel on YouTube, there's a video from a recent event called Optimize your app's speed and efficiency that has a deeper dive into how to use it about an hour into the video. You might be able to get better performance from your code by isolating the updates to a child view that contains just the Text, but you also may want to look at TimelineView (docs), which specifically designed for cases like this.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’25
Reply to MapKit detailAccessoryView buttons not working on macOS Tahoe
Thanks for filing FB20975128. While we investigate, I suggest switching your buttons to AppKit types as a workaround. It sounds like you're using SwiftUI to share the callout code between macOS and iOS, so I realize the impact of using platform-specific code here, but that will at least give you a path forward while this is investigated. — Ed Ford,  DTS Engineer
Nov ’25
Reply to How to correctly fetch data using SwiftData
My code for the last block: import SwiftUI import SwiftData struct HomeView: View { @Query var profiledata: [allProfileData] //get all profiledata @Environment(.modelContext) private var modelContext @State private var profileImage: Image = Image(DefaultProfile) var body: some View { VStack { profileImage } .onAppear() { let fetchRequest = FetchDescriptor() 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) } //yes, I realize that I could use profiledata.first?.profileImage but I was just checking if profileImageData would save or not } } }
Topic: UI Frameworks SubTopic: General Tags:
Nov ’25
EditButton selection gets cleared when confirmationDialog appears in SwiftUI List
I'm experiencing an issue where my List selection (using EditButton) gets cleared when a confirmationDialog is presented, making it impossible to delete the selected items. Environment: Xcode 16.0.1 Swift 5 iOS 18 (targeting iOS 17+) Issue Description: When I select items in a List using EditButton and tap a delete button that shows a confirmationDialog, the selection is cleared as soon as the dialog appears. This prevents me from accessing the selected items to delete them. Code: State variables: @State var itemsSelection = Set() @State private var showDeleteConfirmation = false List with selection: List(currentItems, id: .self, selection: $itemsSelection) { item in NavigationLink(value: item) { ItemListView(item: item) } } .navigationDestination(for: Item.self) { item in ItemViewDetail(item: item) } .toolbar { ToolbarItem(placement: .primaryAction) { EditButton() } } Delete button with confirmation: Button { if itemsSelection.count > 1 { showDeleteConfirmation = true } else { deleteItemsSelected() } } la
1
0
140
Nov ’25
SwiftUI TextField height shrinks on first focus in iOS 26/Xcode 26
Hi Everyone, I’m encountering a layout issue in SwiftUI starting with iOS 26 / Xcode 26 (also reproduced on iPadOS 26). I would like to see whether anyone else has seen the same behaviour, and if there’s any known workaround or fix from Apple. Reproduction Minimal code: struct ContentView: View { @State private var inputText: String = var body: some View { TextField(, text: $inputText) .font(.system(size: 14, weight: .semibold)) .background(Capsule().foregroundStyle(.gray)) } } Environment: Xcode: 26.1 (17B55) Devices / Simulators: iOS 26.0, iOS 26.0.1, iOS 26.1 on iPhone 17 Pro Max; iPadOS 26 on iPad. OS: iOS 26 / iPadOS 26 Observed behaviour When the TextField is tapped for the first time (focus enters), its height suddenly decreases compared to the unfocused state. After this initial focus-tap, subsequent unfocus/focus cycles preserve the height (i.e., height remains “normal” and stable). Prior to iOS 26 (i.e., in older iOS versions) I did not observe this behaviour — same code worked fine. I hav
0
0
104
Nov ’25