Search results for

swiftui

16,581 results found

Post

Replies

Boosts

Views

Activity

Reply to Handling Keyboard Hotkeys and Shortcuts across Multiple Languages
Generally, non-Latin keyboards like Arabic switch to Latin when ⌘ (Command) is pressed, to allow pressing ⌘P. The letter P is also written on Apple’s keyboards as an indication for this use case. That said you’re correct, not all shortcuts defined in QWERTY are doable on all other keyboard layouts. That’s why AppKit, UIKit, and SwiftUI apps automatically localize keyboard shortcuts. Developers are encouraged to define the shortcuts in QWERTY – English (also called “ABC”), and then at runtime they’ll adapt automatically for the user’s current input method & language directionality. Many parameters are taken into account to compute the best hotkey equivalent, for hundreds of keyboard layouts, and left-to-right vs. right-to-left. For instance, ⌘[ is ⌘] in right-to-left, or ⌘^ in ABC – AZERTY. The system is taking care of localizing menus & shortcut display. There is no API currently for your shortcut customization panel to fetch the localized shortcut display like OS menus do. You can request an
2w
Reply to Metal not working in Swift Playgrounds (SSC Scene)
@Graphics and Games Engineer Thanks for the suggestion! I am trying to follow it and trying to compile shaders dynamically, so that I can use them as effects in SwiftUI, but it does not work. What I am doing is this (please don’t mind forced unwrapping): let shaderURL = Bundle.main.url(forResource: example-swiftui-shaders, withExtension: txt)! let source = try! String(contentsOf: shaderURL, encoding: .utf8) do { let device = MTLCreateSystemDefaultDevice()! let opt = MTLCompileOptions() opt.enableLogging = true let library = try device.makeLibrary( source: source, options: opt) print(ok, library) } catch { print(error, error) } I am getting a compilation error: Error Domain=MTLLibraryErrorDomain Code=3 program_source:10:10: fatal error: 'SwiftUI/SwiftUI_Metal.h' file not found #include ^~~~~~~~~~~~~~~~~~~~~~~~~ program_source:10:10: note: did not find header 'SwiftUI_Metal.h' in framework 'SwiftUI' (loaded from '/System/Library/Frameworks') UserInfo={NSLocalizedDescription
2w
Tapping on ShareLink crashes the app
Overview Tapping on ShareLink crashes the app when ShareLink is added in the toolbar with the placement of secondaryAction Feedback FB21337385 Note: Apple engineers please priorities this is a blocker and affects production apps and prevents us from going live. Environment Xcode: 26.2 (17C52) iOS: 26.2 iPadOS: 26.2 Reproduce Able to reproduce 100% both on Simulator and Device Isolation of the crash The crash happens only when the ShareLink is used with the placement .secondaryAction The crash doesn't 'happen when the ShareLink is used with the placement .primaryAction Code import SwiftUI struct ContentView: View { var body: some View { NavigationStack { Text(Hello, world!) .toolbar { ToolbarItem(placement: .primaryAction) { Button(Dummy) { print(dummy) } } // Tapping on share button will cause it to crash // Crash only happens when the ShareLink is used with placement .secondaryAction // It doesn't crash when placement is primaryAction ToolbarItem(placement: .secondaryAction) { ShareLink(item: Some s
1
0
95
2w
Capture a List selection AND push a view
I've got a situation where I want the iPad to push an editing view onto the sidebar (like on iPhone) and also display a detail view (no content view). This is working great. However, I need to determine which item from a List in a NavigationSplitView has been selected and pass this to the detail view (the selection is out of scope). This works with the List selection parameter, but the item selected is ONLY selected and the child view in the NavigationLink does not get pushed, nor does the detail view get changed. I either need to figure out a way to capture the selection without the List Selection parameter (Tap Gesture?) or get the navigation to happen even when using the Selection parameter. I'd appreciate some ideas as I'm a newb just learning SwiftUI.
Topic: UI Frameworks SubTopic: SwiftUI
0
0
42
2w
SwiftUI recursive list with children: programmatically expand nodes
I have a SwiftUI recursive list, created with the (children:) initializer, just like it's shown in the code example here: https://developer.apple.com/documentation/SwiftUI/List#Creating-hierarchical-lists I would like this tree view to be searchable (i.e a user enters a query into a text field and it searches the entire tree at all levels). Displaying a search result which is not at the top level would require its parents to be programmatically expanded. How to programmatically expand certain levels of such a list?
0
0
53
2w
Vision face landmarks shifted on iOS 26 but correct on iOS 18 with same code and image
I'm using Vision framework (DetectFaceLandmarksRequest) with the same code and the same test image to detect face landmarks. On iOS 18 everything works as expected: detected face landmarks align with the face correctly. But when I run the same code on devices with iOS 26, the landmark coordinates are outside the [0,1] range, which indicates they are out of face bounds. Fun fact: the old VNDetectFaceLandmarksRequest API works very well without encountering this issue How I get face landmarks: private let faceRectangleRequest = DetectFaceRectanglesRequest(.revision3) private var faceLandmarksRequest = DetectFaceLandmarksRequest(.revision3) func detectFaces(in ciImage: CIImage) async throws -> FaceTrackingResult { let faces = try await faceRectangleRequest.perform(on: ciImage) faceLandmarksRequest.inputFaceObservations = faces let landmarksResults = try await faceLandmarksRequest.perform(on: ciImage) ... } How I show face landmarks in SwiftUI View: private func convert( point: NormalizedPoint, faceBo
0
0
139
2w
Reply to Metal toolchain compilation error after migration to MacOS 26 and XCode 26.1
Thanks. Couldn't succeed after many tries of downloading and install (errors about permissions to read or execute...). I succeeded following the protocol described here: https://medium.com/@sergey-pekar/how-to-fix-annoying-xcode-26-not-building-swiftui-previews-error-cannot-execute-tool-metal-due-49564e20357c What I dont understand is that on my M1Max MBP, Metal was already OK without any setting, and I could compile my project once XCode 26 was downloaded and installed
2w
Reply to SwiftUI Instrumentation Fails to start
Like @vade above, trying to instrument a macOS app fails for me with the following unhelpful error message: Failed to start the recording: Failed starting ktrace session. Reading the comments above about iOS requiring iOS 26 to run the SwiftUI instrument, I’m now assuming that the same applies to macOS (I’m on 15.7.2). It would save everybody some confusion and time if it was made clear in Instruments that the SwiftUI instrument is not available for pre-26 targets. Ideally, disabling the SwiftUI instrument in the selection panel and having a help tip pop-up when hovering over it explaining that it requires 26 or later.
3w
tabBarMinimizeBehavior behavior in iOS 26
I'm trying to revamp the player into a floating style like Apple music. I use tabViewBottomAccessory with tabBarMinimizeBehavior. At the time, I noticed an issue that tabViewBottomAccessory would not automatically collapse when the scroll area was small (but still exceeded the screen height). tabViewBottomAccessory can only be automatically collapsed when the scroll area is large enough. Below is the simplest demo. I'm not sure if it's intentional or if it's a bug. Besides, I wonder if we can control it programmatically(expanded/inline)? struct ContentView: View { var body: some View { TabView { Tab(Numbers, systemImage: number.circle) { List { // 200 works well, but 20 not ForEach(0..<200) { index in Text((index)) } } } } .tabBarMinimizeBehavior(.onScrollDown) .tabViewBottomAccessory { HStack { Text(SwiftUI Demo App) } } } }
1
0
132
3w
How to improve my SwiftUI tvOS app flow?
Hello, I'm thinking about how to improve my main tvOS app flow, naively I want to do something like this: import Combine import SwiftUI enum AppState { case login, onboarding, main } class AppStateManager { let appStatePublisher = PassthroughSubject() func updateState(_ appState: AppState) } struct tvOSApp: App { private var appState: AppState = .login private let appStateManager = AppStateManager() var body: some Scene { WindowGroup { ZStack { switch appState { case .login: LoginView() case .onboarding: OnboardingView() case .main: MainView() } } .onReceive(appStateManager.appStatePublisher) { self.appState = $0 } } } } So basically, MainView, OnboardingView and LoginView would be the main navigation views of my app, and the appStateManager would be a dependency passed to each of these views and allowing me to update the currently displayed view in the app. (of course I could use an Environment object instead for a 100% SwiftUI solution). I was wondering, however, if there is a better way t
0
0
53
3w
Reply to @state update not reflecting on UI.
Thanks for the post. Let's make sure there is no regression in the new version affecting state management in SwiftUI views. Only happens in iOS 26.1? What about 26.2? As a temporary workaround, you can try explicitly forcing a view update using the method on your view model or directly on the view if you're not using a view model. Do you have a focused sample project that shows the issue? Do you do something like this inside your view? @State private var counter = 0 var body: some View { VStack { Text(Counter: (counter)) .padding() Button(Increment) { counter += 1 (...) Please submit a focused sample for your specific case. It would help if you can provide a minimal reproducible example project demonstrating the issue. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project. Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
3w
How do I prevent screenshots using SwiftUI?
Hi Team, How do I prevent screenshots using SwiftUI. I was using this solution on UIKit: extension UIView { func makeSecure() { DispatchQueue.main.async { let protectedView = UIView() self.superview?.addSubview(protectedView) // constraints... let secureView = SecureView() self.superview?.addSubview(secureView) // constraints... secureView.addSecureSubview(self) // constraints... } } } class SecureView: UIView { private lazy var secureField: UIView = { var secureField: UIView = UIView() // ... if let secureContainer = SecureField().secureContainer { secureField = secureContainer } ... return secureField }() required init() { ... } } Is it posible to do the same thing using SwiftUI. Do we have an example? What would you recommend when we work with confidencial information in SwiftUI like bank account information? Thanks in advance!
0
0
133
3w
How to set the custom DNS with the Network client
We are facing a DNS resolution issue with a specific ISP, where our domain name does not resolve correctly using the system DNS. However, the same domain works as expected when a custom DNS resolver is used. On Android, this is straightforward to handle by configuring a custom DNS implementation using OkHttp / Retrofit. I am trying to implement a functionally equivalent solution in native iOS (Swift / SwiftUI). **Android Reference (Working Behavior) : ** val dns = DnsOverHttps.Builder() .client(OkHttpClient()) .url(https://cloudflare-dns.com/dns-query.toHttpUrl()) .bootstrapDnsHosts(InetAddress.getByName(1.1.1.1)).build() OkHttpClient.Builder().dns(dns).build() **Attempted iOS Approach ** I attempted the following approach : Resolve the domain to an IP address programmatically (using DNS over HTTPS) Connect directly to the resolved IP address Set the original domain in the Host HTTP header **DNS Resolution via DoH : ** func resolveDomain(domain: String) async throws -> String { guard let url = URL
1
0
162
3w
Zoom navigation transitions for tabViewBottomAccessory are not working in SwiftUI with ObservableObject or Observable
The zoom navigation transition with matchedTransitionSource in tabViewBottomAccessory does not work when a Published var in an ObservableObjector Observable gets changed. Here is an minimal reproducible example with ObservableObject: import SwiftUI import Combine private final class ViewModel: ObservableObject { @Published var isPresented = false } struct ContentView: View { @Namespace private var namespace @StateObject private var viewModel = ViewModel() // @State private var isPresented = false var body: some View { TabView { Button { viewModel.isPresented = true } label: { Text(Start) } .tabItem { Image(systemName: house) Text(Home) } Text(Search) .tabItem { Image(systemName: magnifyingglass) Text(Search) } Text(Profile) .tabItem { Image(systemName: person) Text(Profile) } } .sheet(isPresented: $viewModel.isPresented) { Text(Sheet) .presentationDragIndicator(.visible) .navigationTransition(.zoom(sourceID: tabViewBottomAccessoryTransition, in: namespace)) } .tabViewBottomAccessory { Button { viewMo
0
0
87
3w