Hi,
I'm looking to build something similar to the header blur in the App Store and Apple TV app settings. Does anyone know the best way to achieve this so that when there is nothing behind the header it looks the same as the rest of the view background but when content goes underneath it has a blur effect. I've seen .scrollEdgeEffect on IOS26 is there something similar for visionOS?
Thanks!
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Posts under SwiftUI tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
List {
Text("ITEM 1")
.onHover(perform: { hovering in
debugPrint("hovering: ", hovering)
})
.help("ITEM 1")
Text("ITEM 2")
.onHover(perform: { hovering in
debugPrint("hovering: ", hovering)
})
.help("ITEM 2")
Text("ITEM 3")
.onHover(perform: { hovering in
debugPrint("hovering: ", hovering)
})
.help("ITEM 3")
}
.fixedSize(horizontal: false, vertical: true)
.frame(maxHeight: 200)
}
Hello everyone!!!
Considering the snippet above, seems like the onHover action, including help modifiers, doesn't work for the elements of a List, on macOS Tahoe.
The situation changes using a ScrollView embedding a LazyVStack, or disabling Liquid Glass from the info plist, so my guess is that the new Liquid Glass style has something to do with this issue though I didn't find any clue about it.
Does anyone have any idea?
Maybe there's a layer above that doesn't allow to trigger the onHover modifier?
Thanks in advance for your help!
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()
}```
I’m testing .glassEffect() in a widget on the latest iOS 26 beta, but it seems to have no effect at all — the blur isn’t visible, and in some cases even white text disappears completely.
Is this the expected behavior for widgets (i.e. glass effect is not supported), or could this be a bug in the beta?
Would appreciate any clarification or pointers. Thanks!
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 this issue?
Hi! I am adding MacOS to a SwiftUI based multiplatform app in XCode, and have noticed an effect on the OTF font I am using. When started for a MacOSX target, the font looks a bit fuzzy, or too bold for the same display:
Above is the display running in an iPhone 13 mini simulator, below the macOS version running for the "My Mac" target.
The font is in both cases just fetched with
static let tkDisplayFont = Font.custom("Segment7Standard", size: 38)
Same applies in dark mode:
This makes the numbers and especially the decimal point a bit harder to read. The same happens with the system font, but it is not such a problem there:
I guess this is handled a bit differently between UIFont and NSFont underneath. Is there a way to tell the font to behave the same way as on iOS?
Calls to NavigationPath.removeLast(_:) will successfully remove items from the path, but the navigation stack UI fails to correctly update if a view in an intermediate path item had a focused searchable modifier.
In this first video, the searchable modifier is unused. I can navigate to the list, make a selection and return home:
In this second example, the searchable modifier is focused and a selection from the list is made. In the final screen, if I attempt to return home we can see that the navigation path size decreases but the view does not change. If the button is pressed again, we attempt to remove path items that no longer exist, causing a fatal error.
Minimal Reproducible Code:
import SwiftUI
@main
struct NavigationStackRemoveLastNBugApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State private var navigationPath = NavigationPath()
var body: some View {
NavigationStack(path: $navigationPath) {
List {
Button("List") {
navigationPath.append(NavigationDestination.listView)
}
}
.navigationDestination(for: NavigationDestination.self) { destination in
switch destination {
case let .selectionView(int):
SelectionView(selectedNumber: int)
case .listView:
ListView()
}
}
.navigationTitle("Home")
}
.environment(\.navigationPath, $navigationPath)
}
}
enum NavigationDestination: Hashable {
case listView
case selectionView(Int)
}
struct ListView: View {
@Environment(\.navigationPath) var navigationPath
@State private var query = ""
var body: some View {
List(1..<5, id: \.self) { int in
Button {
navigationPath?.wrappedValue.append(NavigationDestination.selectionView(int))
} label: {
Text(int, format: .number)
}
}
.searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always))
}
}
struct SelectionView: View {
@Environment(\.navigationPath) var navigationPath
let selectedNumber: Int
@State private var pathSize: Int?
var body: some View {
List {
LabeledContent("Selection", value: selectedNumber.formatted())
if let pathSize {
LabeledContent("Navigation Path Size", value: pathSize.formatted())
}
Button("Back Home") {
navigationPath?.wrappedValue.removeLast(2)
pathSize = navigationPath?.wrappedValue.count
}
}
.task {
pathSize = navigationPath?.wrappedValue.count
}
}
}
extension EnvironmentValues {
@Entry var navigationPath: Binding<NavigationPath>?
}
#Preview {
ContentView()
}
FB20395585
On macOS Tahoe 26, NSSplitViewController introduced the NSSplitViewItemAccessoryViewController and related-APIs in NSSplitViewController, such as addBottomAlignedAccessoryViewController(_:).
Those APIs allow you to place accessory views at the top and bottom of a split view with a nice edge effect.
I understand how to use them with AppKit. However, I’m not sure how to achieve the same functionality with SwiftUI.
Environment
iOS 26 (23A343)
Xcode 26
Reproduces on device and Simulator
Description
When presenting a SwiftUI WebView (native iOS 26 component) or a WKWebView/UIWebView via UIViewRepresentable, focusing a text field inside the web view and then dismissing it breaks the keyboard layout behavior.
After returning to the main app, tapping any TextField causes the keyboard to cover bottom controls (e.g. buttons). Expected safe area insets are not applied.
The issue is only resolved after closing and reopening the keyboard once.
Steps to Reproduce
Open a SwiftUI screen with WebView (via .sheet or NavigationLink).
Inside the web view, tap a text field to show the keyboard.
Dismiss the web view.
Tap a TextField in the main app.
Expected Result
Layout should adjust correctly.
Bottom controls stay visible above the keyboard.
Actual Result
Keyboard covers bottom controls.
Insets are ignored until the keyboard is dismissed and reopened.
Notes
Reproduces with:
Native SwiftUI WebView (iOS 26)
WKWebView and UIWebView via UIViewRepresentable
Presentation style (.sheet or navigation push) does not matter.
Example video: https://youtu.be/Epgoz1vETKU
FB: FB20386257
Sample Code
import SwiftUI
import WebKit
struct ContentView: View {
@State var url: URL?
@FocusState private var isFocused: Bool
var body: some View {
VStack {
TextField("TextField", text: .constant(""))
.focused($isFocused)
Button("HIDE KEYBOARD") { isFocused = false }
Spacer()
Button("ACTION") {
url = URL(string: "https://google.com")
}
}
.sheet(item: $url) { value in
NavigationStack {
WebView(url: value)
.toolbar {
ToolbarItem(placement: .topBarLeading) {
Button("CLOSE") { url = nil }
}
}
}
}
}
}
extension URL: Identifiable {
public var id: String { absoluteString }
}
Environment:
• macOS 26.0 (25A354)
• Xcode 26.0.1 (17A400)
Issue:
Applying .tint(...) to a macOS Liquid Glass style Toggle does not change the background color when the toggle is in the on state.
Expected behavior:
The .tint(...) modifier should apply the chosen color.
Actual behavior:
The toggle remains system blue (accent color), regardless of the tint specified
Notes:
I’m hearing that .tint() behaves normally on iOS, so this may be macOS-specific.
Hi everyone,
I’m experimenting with SwiftUI's new NavigationStack / navigationDestination API.
Normally, when you navigate to a value using NavigationLink(value:) and a matching navigationDestination(for:), the destination view is pushed onto the navigation stack.
What I’d like to know is: Is there a way to present that destination view as a sheet instead of pushing it?
Essentially: Can a NavigationDestination be shown modally?
Here’s a simplified example of what I mean:
struct RootView: View {
var body: some View {
NavigationStack {
NavigationLink(value: "Example") {
Text("Push me!")
}
.navigationDestination(for: String.self) { _ in
DetailView() // <--- Can this be shown as a sheet?
}
}
}
}
My questions are:
Is there a built‑in way to make a navigationDestination present modally (as .sheet) instead of pushing?
If not, is the recommended approach to handle .sheet state manually outside of the NavigationStack and bypass navigationDestination for such cases?
Can the NavigationPath itself somehow encode a modal presentation style for certain types?
Thanks in advance for any tips or confirmation that this is (not) possible in SwiftUI.
The code is shown as follows. Once the tabViewBottomAccessory is enabled, the tabViewSidebarBottomBar disappears.
TabView {
Text("tab a")
.tabItem {
Image(systemName: "a.square")
Text("Tab A")
}
.ignoresSafeArea(edges: [.all])
Text("tab b")
.tabItem {
Image(systemName: "b.square")
Text("Tab B")
}
.ignoresSafeArea(edges: [.all])
}
//.tabViewBottomAccessory {
// Text("tabViewBottomAccessory")
//}
.tabBarMinimizeBehavior(.onScrollDown)
.tabViewStyle(.sidebarAdaptable)
.tabViewSidebarBottomBar {
Text("tabViewSidebarBottomBar")
}
In the ScoreKeeper tutorial there's the following code:
ForEach($players) { $player in
GridRow {
TextField("Name", text: $player.name)
Text("\(player.score)")
Stepper("\(player.score)", value: $player.score)
.labelsHidden()
}
}
Can someone please explain why the 2 instances of "player.score" are not preceded by "$". Thanks!
macos 26, xcode 26, ios 26. Everytime when you add new line at some point (like after 10-20 lines) the TextField will ignore the lineLimit and start changing the height.
The problem related to Form but not Scroll.
Maybe it can be reproduced in other scroll-based views.
Bug report opened.
Any siggestions?
struct Test: View {
@State var text = ""
var body: some View {
Form {
Section {
TextField("", text: $text, axis: .vertical)
.lineLimit(3)
.background(Color.green)
}
}
}
}
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
Test()
}
}
}
Hi all,
I’m working on a UIKit app where I embed a SwiftUI TextField using UIHostingController. I’m using an ObservableObject model to drive the textfield content:
class TextFieldModel: ObservableObject {
@Published var text: String
@Published var placeholder: String
@Published var isSecure: Bool
@Published var isFocused: Bool
init(pText: String, pPlaceholder: String, pIsSecure: Bool, pIsFocused: Bool) {
self.text = pText
self.placeholder = pPlaceholder
self.isSecure = pIsSecure
self.isFocused = pIsFocused
}
}
And my SwiftUI view:
struct TextFieldUI: View {
@ObservedObject var pModel: TextFieldModel
@FocusState private var pIsFocusedState: Bool
var body: some View {
TextField(pModel.placeholder, text: $pModel.text)
.focused($pIsFocusedState)
}
}
I embed it in UIKit like this:
let swiftUIContentView = TextFieldUI(pModel: model)
let hostingController = UIHostingController(rootView: swiftUIContentView)
addChild(hostingController)
view.addSubview(hostingController.view)
hostingController.didMove(toParent: self)
Question:
In UIKit, if I subclass UITextField, I can override insertText(_:) and choose not to call super, effectively preventing the textfield from updating when the user types.
Is there a SwiftUI equivalent to intercept and optionally prevent user input in a TextField, especially when it’s embedded inside UIKit?
What is the recommended approach in SwiftUI for this?
I’m running into an issue with TextField focus behavior in SwiftUI.
By default, when I set focus to a TextField programmatically (using @FocusState), SwiftUI behaves like AppKit — the entire contents of the text field are selected. This is causing problems for my use case, because I want the caret placed at the end of the text without selecting everything.
How I solved this in AppKit
In AppKit, I worked around this by subclassing NSTextField and overriding becomeFirstResponder to adjust the editor’s selection:
override func becomeFirstResponder() -> Bool {
let responderStatus = super.becomeFirstResponder()
// Ensure caret is placed at the end, no text selected
if let editor = self.currentEditor() {
let selectedRange = editor.selectedRange
editor.selectedRange = NSRange(location: selectedRange.length, length: 0)
}
return responderStatus
}
This successfully prevented AppKit from auto-selecting the entire string when focus changed.
The problem in SwiftUI
Now I see the same auto-select behavior in SwiftUI when I toggle focus with @FocusState. But unlike AppKit, SwiftUI doesn’t expose the underlying NSTextView or UITextField APIs, so I can’t directly adjust the selection or caret position.
Questions:
Is there a way in SwiftUI to control the caret/selection behavior when a TextField becomes focused?
Is there a built-in modifier or @FocusState trick I’m missing?
Has anyone found a reliable SwiftUI-idiomatic approach to ensure the caret is placed at the end of the text instead of selecting all text?
update:
adding my swiftUI code below:
struct TextFieldUI: View {
@ObservedObject var pModel:TextFieldModel
@FocusState private var pIsFocusedState: Bool
var body: some View {
VStack(spacing: 20) {
TextField(pModel.placeholder, text: $pModel.text)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
.focused($pIsFocusedState)
.onChange(of: pModel.isFocused) { old, newValue in
pIsFocusedState = newValue
}
.onChange(of: pIsFocusedState) { old, newValue in
pModel.isFocused = newValue
}
.onAppear {
pIsFocusedState = pModel.isFocused
}
Toggle("Secure Mode", isOn: $pModel.isSecure)
.padding()
}
.padding()
}
}
In iOS 18 the following code works to set a state variable when you hold your finger on the Text() field (well, the ScrollView()), but it doesn't work in iOS 26:
@State private var pressed: Bool = false
...
ScrollView {
VStack {
Text("Some text goes here")
}.frame(maxWidth: .infinity)
}
.onTapGesture {} // This is required to allow the long press gesture to be recognised
.gesture(
DragGesture(minimumDistance: 0)
.onChanged({ _ in
pressed = true
})
.onEnded({ _ in
pressed = false
})
)
.background(pressed ? .black.opacity(0.4) : .clear)
I've tried changing this to:
var dragGesture: some Gesture {
DragGesture(minimumDistance: 0)
.onChanged({ _ in self.pressed = true })
.onEnded({ _ in self.pressed = false })
}
...
ScrollView {
VStack {
Text("Some text goes here")
}.frame(maxWidth: .infinity)
}
.gesture(dragGesture)
.background(pressed ? .black.opacity(0.4) : .clear)
And this:
var longPress: some Gesture {
LongPressGesture(minimumDuration: 0.25)
.onChanged({ _ in self.pressed = true })
.onEnded({ _ in self.pressed = false })
}
...
ScrollView {
VStack {
Text("Some text goes here")
}.frame(maxWidth: .infinity)
}
.gesture(longPress)
.background(pressed ? .black.opacity(0.4) : .clear)
Neither works.
Any ideas? Thanks.
Hi everyone,
I have the following issue that I have tried to tweak every possible modifier of ScrollView and still got the same result in iOS 26.
Description:
Create a SwiftUI ScrollView with scrollTargetBehavior of paging, also create a bottom UI view below the ScrollView.
If the starting index is not 0, the position of current page will be off with part of previous page shown above it.
It only happens on iOS 26, not on iOS 18.
Also if bottom UI view (text view in this case) is removed, it also works fine.
I want to see if there is a solution for it or it's an iOS 26 bug. Thanks!
import SwiftUI
struct ContentView: View {
@State private var currentPageIndex: Int? = 3
var body: some View {
VStack {
scrollView
Text("Bottom Bar")
.frame(maxWidth: .infinity)
.frame(height: 80)
.background(.red)
}
.background(.black)
}
@ViewBuilder
var scrollView: some View {
VerticalPagerView(
currentPageIndex: $currentPageIndex,
itemCount: 10,
content: Array(0...9).map { index in
content(for: index)
}
)
}
@ViewBuilder
private func content(for index: Int) -> some View {
// Empty view with random background color
Color(
red: Double((index * 25 + 0) % 255) / 255.0,
green: Double((index * 25 + 80) % 255) / 255.0,
blue: Double((index * 25 + 160) % 255) / 255.0
)
}
}
struct VerticalPagerView<Content: View>: View {
@Binding private var currentPageIndex: Int?
private let itemCount: Int
private let content: [Content]
init(
currentPageIndex: Binding<Int?>,
itemCount: Int,
content: [Content]
) {
self._currentPageIndex = currentPageIndex
self.itemCount = itemCount
self.content = content
}
var body: some View {
GeometryReader { geometryReader in
ScrollViewReader { reader in
ScrollView(.vertical) {
LazyVStack(spacing: 0) {
ForEach(0 ..< itemCount, id: \.self) { index in
content[index]
.id(index)
.containerRelativeFrame(.vertical, alignment: .center)
.clipped()
}
}
.frame(minHeight: geometryReader.size.height)
.scrollTargetLayout()
}
.scrollIndicators(.hidden)
.onAppear {
guard let currentPageIndex = currentPageIndex else { return }
reader.scrollTo(currentPageIndex, anchor: .center)
}
}
.scrollPosition(id: $currentPageIndex, anchor: .center)
.ignoresSafeArea()
.scrollTargetBehavior(.paging)
.onChange(of: currentPageIndex) { oldIndex, newIndex in
}
}
}
}
Hi community:
I noticed that each closure is counted as lines in code coverage (unit tests) (Xcode 14.1.0) in a swiftUI File. I mean, If you coded and VStack that involves another HStack, and HStack contains 4 lines, and the VStack contains 6 lines counting the HStack. The total executable lines should be 6 (6 lines in the file). But Xcode count 10, counting twice the HStack lines.
Is it a bug, or is it correct? You know, I don't know if Apple has another concept about executable lines.
Also, Is it possible to remove previews with any configuration from code coverage or constant files?
Thanks for all.
I am working on a SwiftUI project using Core Data. I have an entity called AppleUser in my data model, with the following attributes: id (UUID), name (String), email (String), password (String), and createdAt (Date). All attributes are non-optional.
I created the corresponding Core Data class files (AppleUser+CoreDataClass.swift and AppleUser+CoreDataProperties.swift) using Xcode’s automatic generation. I also have a PersistenceController that initializes the NSPersistentContainer with the model name JobLinkModel.
When I try to save a new AppleUser object using:
let user = AppleUser(context: viewContext)
user.id = UUID()
user.name = "User1"
user.email = "..."
user.password = "password1"
user.createdAt = Date()【The email is correctly formatted, but it has been replaced with “…” for privacy reasons】
try? viewContext.save()
I get the following error in the console:Core Data save failed: Foundation._GenericObjCError.nilError, [:]
User snapshot: ["id": ..., "name": "User1", "email": "...", "password": "...", "createdAt": ...]
All fields have valid values, and the Core Data model seems correct. I have also tried:
• Checking that the model name in NSPersistentContainer(name:) matches the .xcdatamodeld file (JobLinkModel)
• Ensuring the AppleUser entity Class, Module, and Codegen are correctly set (Class Definition, Current Product Module)
• Deleting duplicate or old AppleUser class files
• Cleaning Xcode build folder and deleting the app from the simulator
• Using @Environment(.managedObjectContext) for the context
Despite all this, I still get _GenericObjCError.nilError when saving a new AppleUser object.
I want to understand:
1. Why is Core Data failing to save even though all fields are non-nil and correctly assigned?
2. Could this be caused by some residual old class files, or is there something else in the setup that I am missing?
3. What steps should I take to ensure that Core Data properly recognizes the AppleUser entity and allows saving?
Any help or guidance would be greatly appreciated.