have a SwiftUI View where I can edit financial transaction information. The data is stored in SwiftData. If I enter a TextField element and start typing, it is super laggy and there are hangs of 1-2 seconds between each input (identical behaviour if debugger is detached). On the same view I have another TextField that is just attached to a @State variable of that view and TextField updates of that value work flawlessly. So somehow the hangs must be related to my SwiftData object but I cannot figure out why.
This used to work fine until a few months ago and then I could see the performance degrading.
I have noticed that when I use a placeholder variable like
@State private var transactionSubject: String = ""
and link that to the TextField, the performance is back to normal. I am then using
.onSubmit {
self.transaction.subject = self.transactionSubject
}
to update the value in the end but this again causes a 1 s hang. :/
Below the original code sample with some unnecessary stuff removed:
struct EditTransactionView: View {
@Environment(\.modelContext) var modelContext
@Environment(\.dismiss) var dismiss
@State private var testValue: String = ""
@Bindable var transaction: Transaction
init(transaction: Transaction) {
self.transaction = transaction
let transactionID = transaction.transactionID
let parentTransactionID = transaction.transactionMasterID
_childTransactions = Query(filter: #Predicate<Transaction> {item in
item.transactionMasterID == transactionID
}, sort: \Transaction.date, order: .reverse)
_parentTransactions = Query(filter: #Predicate<Transaction> {item in
item.transactionID == parentTransactionID
}, sort: \Transaction.date, order: .reverse)
print(_parentTransactions)
}
//Function to keep text length in limits
func limitText(_ upper: Int) {
if self.transaction.icon.count > upper {
self.transaction.icon = String(self.transaction.icon.prefix(upper))
}
}
var body: some View {
ZStack {
Form{
Section{
//this one hangs
TextField("Amount", value: $transaction.amount, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
//this one works perfectly
TextField("Test", text: $testValue)
HStack{
TextField("Enter subject", text: $transaction.subject)
.onAppear(perform: {
UITextField.appearance().clearButtonMode = .whileEditing
})
Divider()
TextField("Select icon", text: $transaction.icon)
.keyboardType(.init(rawValue: 124)!)
.multilineTextAlignment(.trailing)
}
}
}
.onDisappear(){
if transaction.amount == 0 {
// modelContext.delete(transaction)
}
}
.onChange(of: selectedItem, loadPhoto)
.navigationTitle("Transaction")
.navigationBarTitleDisplayMode(.inline)
.toolbar{
Button("Cancel", systemImage: "trash"){
modelContext.delete(transaction)
dismiss()
}
}
.sheet(isPresented: $showingImagePickerView){
ImagePickerView(isPresented: $showingImagePickerView, image: $image, sourceType: .camera)
}
.onChange(of: image){
let data = image?.pngData()
if !(data?.isEmpty ?? false) {
transaction.photo = data
}
}
.onAppear(){
cameraManager.requestPermission()
setDefaultVendor()
setDefaultCategory()
setDefaultGroup()
}
.sheet(isPresented: $showingAmountEntryView){
AmountEntryView(amount: $transaction.amount)
}
}
}
}
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
In my own fairly complex DocumentGroup app, I've been having a problem with bottom bar items appearing briefly when first drawn, and then disappearing. This seems to be caused by the invalidation of one or more views in the hierarchy.
In Apple's own WritingApp, which is designed to demonstrate DocumentGroup, adding a bottom bar item to the toolbar demonstrates the problem:
This toolbar is on the StoryView:
ToolbarItem() {
Button("Show Story", systemImage: "book") {
isShowingSheet.toggle()
}
.sheet(isPresented: $isShowingSheet) {
StorySheet(story: document.story, isShowingSheet: $isShowingSheet)
.presentationSizing(.page)
}
}
// This does not persist
ToolbarItem(placement: .bottomBar) {
Button("Foo") { }
}
}
My 'Foo' button is new. What happens is that it persists for a few seconds; its disappearance coincides with the writing of the file to disk, it seems. I would dearly like it to persist! I've tried adding an ID, setting the toolbar visibility and so on, but no luck. Anyone had this working?
Topic:
UI Frameworks
SubTopic:
SwiftUI
I want to check if this behaviour is legit in iOS 26 Beta:
We have an admittedly stranger setup where a child view controller acts as a TabBar and is a UIHostingController so that we can use SwiftUI for the tab bar items.
One of the tab pages has a scrollview whose content (imagine a chat view) might go from a lighter aspect to darker colors and back when scrolling.
When we scroll to predominantly dark bubbles, the trait of the tabBar changes to dark mode.
The function traitCollectionDidChange() on the UIHostingController is called ! but only for the tabBar controller.
I know that in iOS there is some blending going on at the tabBar level when scrolling, but changing just one view + subviews to dark mode, automatically, instead of user triggered? It might be some optimisation if the view is considered opaque? But then I would expect to not change anything visually, if opaque.
Is this expected behaviour on iOS 26?
And if so, can we disable it? But just this blending/ trait changing, and keep the user triggered trait changes.
Topic:
UI Frameworks
SubTopic:
SwiftUI
I’m facing an issue and I’d like to know if anyone has already run into this.
I have a ContentView that presents a SettingsView as a sheet. SettingsView applies a change to the app’s colorScheme. ContentView reacts correctly to the change, and SettingsView does too (so far, so good).
What’s strange is that when I set nil on the preferredColorScheme modifier (which, according to the docs, corresponds to the system color scheme), ContentView correctly picks up the change and refreshes, while SettingsView does pick up the change but doesn’t refresh. (In the video you can clearly see that when I switch from Dark to System, the parent view refreshes properly but not the presented sheet.)
I’ve tried everything—switching to UIKit, changing the sheet’s ID… nothing works
Another strange thing: if I present SettingsView through a NavigationLink, everything works normally…
Here is a sample code to reproduce:
import SwiftUI
enum AppTheme: Int {
case system = 0
case dark = 1
case light = 2
var colorScheme: ColorScheme? {
switch self {
case .system: return nil
case .light: return .light
case .dark: return .dark
}
}
}
struct SettingsView: View {
@AppStorage("theme") var appTheme: AppTheme = .system
var body: some View {
VStack(spacing: 8) {
Button {
select(theme: .system)
} label: {
Text("Systeme")
}
Button {
select(theme: .dark)
} label: {
Text("Dark")
}
Button {
select(theme: .light)
} label: {
Text("Light")
}
}
.preferredColorScheme(appTheme.colorScheme)
}
func select(theme: AppTheme) {
appTheme = theme
}
}
struct ContentView: View {
@AppStorage("theme") var appTheme: AppTheme = .system
@State var isPresented = false
var body: some View {
NavigationStack {
VStack {
Button {
isPresented = true
} label: {
Text("Present settings")
}
// NavigationLink("Present settings") {
// SettingsView()
// }
}
.preferredColorScheme(appTheme.colorScheme)
.sheet(isPresented: $isPresented) {
SettingsView()
}
}
}
}
#Preview {
ContentView()
}
When using a NavigationSplitView in a DocumentGroup, SwiftUI renders incorrect UI and doesn’t let the user navigation between the sidebar and detail views.
Even the default Xcode project template “Document App” doesn’t work.
Steps to reproduce
Create a new project and use the Document App template.
Run the project on either iPad or iPhone running iOS 26 beta 9
Experience the following issues.
On iPhone
The back button (to return to the document browser) and the document title are rendered two times.
When viewing the detail of an item, by navigating to the detail view, you cannot go back to the list of items, because the back button brings you back to the document browser.
The same issues are also present on iPad.
I've tested this on an iPad and iPhone running iOS 26 beta 9 and Xcode 26.0 beta 7.
I've reported this issue already → FB20062294
Topic:
UI Frameworks
SubTopic:
SwiftUI
Hey there! I've been tracking a really weird behavior with a List backed by @FetchRequest from CoreData.
When I toggle a bool on the CoreData model, the first time it updates correctly, but if I do it a second time, the UI doesn't re-render as expected. This does not happen if I compile the app using Xcode 16 (targeting both iOS 18 and iOS 26), nor it happens when using Xcode 26 and targeting iOS 18. It only happens when building the app using Xcode 26 and running it on iOS 26.
Here are two demos: the first one works as expected, when I toggle the state twice, both times updates. The second one, only on iOS 26, the second toggle fails to re-render.
Demo (running from Xcode 16):
Demo (running from Xcode 26):
The code:
import SwiftUI
import CoreData
@main
struct CoreDataTestApp: App {
let persistenceController = PersistenceController.shared
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.managedObjectContext, persistenceController.container.viewContext)
}
}
}
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)])
private var items: FetchedResults<Item>
var body: some View {
NavigationView {
List {
ForEach(items) { item in
HStack {
Text(item.timestamp!.formatted())
Image(systemName: item.isFavorite ? "heart.fill" : "heart").foregroundStyle(.red)
}.swipeActions(edge: .leading, allowsFullSwipe: true) {
Button(item.isFavorite ? "Unfavorite" : "Favorite", systemImage: item.isFavorite ? "heart" : "heart.fill") {
toggleFavoriteStatus(item: item)
}
}
}
}
.toolbar {
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
}
}
private func addItem() {
withAnimation {
let newItem = Item(context: viewContext)
newItem.timestamp = Date()
newItem.isFavorite = Bool.random()
try! viewContext.save()
}
}
private func toggleFavoriteStatus(item: Item) {
withAnimation {
item.isFavorite.toggle()
try! viewContext.save()
}
}
}
struct PersistenceController {
static let shared = PersistenceController()
let container: NSPersistentContainer
init() {
container = NSPersistentContainer(name: "CoreDataTest")
container.loadPersistentStores(completionHandler: { _, _ in })
container.viewContext.automaticallyMergesChangesFromParent = true
}
}
Hi everyone!
I've encountered an issue on Mac Catalyst: using the latest inspector modifier causes abnormal Sidebar and Columns state in NavigationSplitView.
Sample Code:
struct ContentView: View {
@State private var isPresented = false
var body: some View {
NavigationSplitView {
List {
ForEach(0..<20, id: \.self) { item in
Text("Item \(item)")
}
}
} content: {
List {
ForEach(0..<20, id: \.self) { item in
Text("Item \(item)")
}
}
} detail: {
List {
}
}
.inspector(isPresented: $isPresented) {
Form {
}
}
}
}
Steps to reproduce:
Xcode 16 beta 7, create a new iOS project
Paste the code above
Enable Mac Catalyst
Run on Mac (macOS 15 beta 9)
Press Command+N three times to open 3 new windows
Click the Sidebar Toggle button
The issue occurs (see screenshot below)
Through testing, I found that as long as the inspector modifier is attached, the issue occurs.
Also, the problem only appears in the 3rd and subsequent newly opened windows—the first two windows work as expected.
FB20061521
We are building a CarPlay app and have run into an issue with data updates.
When the app is running on the CarPlay display and the iPhone screen is locked, no data updates are shown on the CarPlay screen. As soon as the phone is unlocked, the data updates appear instantly on the CarPlay display.
Has anyone encountered this behavior before? Is there a specific setting, entitlement, or background mode we need to enable in order to ensure the CarPlay app continues to receive and display data while the iPhone is locked?
Any guidance would be greatly appreciated.
Widget abnormal refresh
My app is a music application. When playing or pausing a song, the status is synchronized to NowPlaying, and the app itself supports widgets. During testing, I found that when pausing or playing music, the widget triggers a timeline refresh, which is completely unexpected. However, switching songs does not cause this.
Looking at Apple’s logs:
By default 21:27:08.094490+0800 mediaremoted Set: origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer setting inferred playback state from to
By default 21:27:08.094607+0800 mediaremoted [MRDNowPlayingPlayerClient] PlaybackState changed from Playing to Paused for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer
By default 21:27:08.094713+0800 mediaremoted [MRDNowPlayingPlayerClient] isPlaying changed to false for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer
By default 21:27:08.111861+0800 mediaremoted Posted Active Now Playing Notification kMRMediaRemoteNowPlayingApplicationPlaybackStateDidChangeNotification for path origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer
By default 21:27:08.115550+0800 mediaremoted Response: handlePlaybackQueueRequest<B0BDBB4E-C539-4D39-B51C-718115EBD7C4 assistantd-2659 /M/L/AF/R[0:1]> returned for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer in 0.0005 seconds
By default 21:27:08.119344+0800 assistantd Response: playbackQueue<B0BDBB4E-C539-4D39-B51C-718115EBD7C4 assistantd-2659 /M/L/AF/R[0:1]> returned <> for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer in 0.0010 seconds
By default 21:27:08.122322+0800 SpringBoard Response: playbackState<63A30582-E3C2-4F4D-AC57-8E5841FAD568> returned for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer in 0.0005 seconds
By default 21:27:08.126132+0800 chronod Observed com.company.musicdev stopped running for exempt reason: nowPlaying - remainingReasons: None By default 21:27:08.126285+0800 chronod [com.company.musicdev::com.company.musicdev.musicdesktopwidget:VisionWidget_medium4158108784:systemMedium:3758765227620768254:338.00/158.00/21.60:(null)~(null)] on local marked as requiring reload
By default 21:27:08.126455+0800 chronod [com.company.musicdev::com.company.musicdev.musicdesktopwidget:VisionWidget_medium4158108784:3758765227620768254] Reload with configuration [systemRequest(sessionEnded)-immediate-free-1] By default 21:27:08.126854+0800 mediaremoted Response: handlePlaybackQueueRequest<ACF764D9-05A6-41FF-8BB5-8CB81A8BC163 assistantd-2659 /M/L/AF/R[0:1]> returned for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer in 0.0008 seconds
By default 21:27:08.127960+0800 assistantd Response: playbackQueue<ACF764D9-05A6-41FF-8BB5-8CB81A8BC163 assistantd-2659 /M/L/AF/R[0:1]> returned <> for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer in 0.0016 seconds
By default 21:27:08.128091+0800 wifid Response: playbackState returned for origin-iPhone-1280262988/client-com.company.musicdev-10059 (music)/player-MediaRemote-DefaultPlayer in 0.0115 seconds
When the music state changes, you can see the widget is triggered to refresh. I want to ask if this is the system’s mechanism? I checked my code and there is no operation to actively refresh the widget when pausing or playing. Can this situation be avoided?
On macOS 26 I can see the dividers when I open my Help menu:
However, on iPadOS 26 the dividers don't appear:
I am simply using Divider() to separate my menu bar items in my CommandGroup.
iPadOS does support dividers as I can see them for the system generated Edit menu but for some reason it's not working here.
Does anyone know if I am doing something wrong with the iPadOS implementation?
Is there a way to get a sheet on the side over an interactive view with a proper glass background on iPad? Ideally, including being able to drag the sheet between medium/large-height sizes (like a sheet with presentationDetents on iPhone), similar to the Maps app:
I tried the NavigationSplitView like in the NavigationCookbook example. This is somewhat like it, but it's too narrow (sidebar-like) and doesn't get the full navigation bar:
I also played around with .sheet and .presentationDetents and the related modifiers, thinking I could make the sheet appear to the side; but no luck here. It seems to have all the correct behaviors, but it's always presented form-like in the center:
Example code for the sheet:
import SwiftUI
import MapKit
struct ContentView: View {
var body: some View {
Map()
.sheet(isPresented: .constant(true)) {
NavigationStack {
VStack {
Text("Hello")
NavigationLink("Show Foo") {
Text("Foo")
.navigationTitle("Foo")
.containerBackground(Color.clear, for: .navigation)
}
}
}
.presentationDetents([.medium, .large])
.presentationBackgroundInteraction(.enabled)
}
}
}
I also tried placing the NavigationStack as an overlay and putting a .glassEffect behind it. From the first sight, this looks okay-ish on beta 3, but seems prone to tricky gotchas and edge cases around the glass effects and related transitions. Seems like not a good approach to me, building such navigational containers myself has been a way too big time-sink for me in the past...
Anyway, example code for the overlay approach:
import SwiftUI
import MapKit
struct ContentView: View {
var body: some View {
Map()
.overlay(alignment: .topLeading) {
NavigationStack {
VStack {
Text("Hello")
NavigationLink("Show Foo") {
ScrollView {
VStack {
ForEach(1...30, id: \.self) { no in
Button("Hello world") {}
.buttonStyle(.bordered)
}
}
.frame(maxWidth: .infinity)
}
.navigationTitle("Foo")
.containerBackground(Color.clear, for: .navigation)
}
}
.containerBackground(Color.clear, for: .navigation)
}
.frame(width: 400)
.frame(height: 600)
.glassEffect(.regular, in: .rect(cornerRadius: 22))
.padding()
}
}
}
Do I miss something here or is this not possible currently with built-in means of the SwiftUI API?
Topic:
UI Frameworks
SubTopic:
SwiftUI
My Xcode project fails to run with the following crash log any time I use a new SwiftUI symbol such as ConcentricRectangle or .glassEffect. I've tried using the legacy linker to no avail. It compiles perfectly fine, and I've tried targeting just macOS 26 also to no avail. This is a macOS project that's compiled just fine for years and compiles and runs on macOS going back to 13.0.
Failed to look up symbolic reference at 0x118e743cd - offset 1916987 - symbol symbolic _____y_____y_____y_____yAAyAAy_____y__________G_____G_____yAFGGSg_ACyAAy_____y_____SSG_____y_____SgGG______tGSgACyAAyAAy_____ATG_____G_AVtGSgtGGAQySbGG______Qo_ 7SwiftUI4ViewPAAE11glassEffect_2inQrAA5GlassV_qd__tAA5ShapeRd__lFQO AA15ModifiedContentV AA6VStackV AA05TupleC0V AA01_hC0V AA9RectangleV AA5ColorV AA12_FrameLayoutV AA24_BackgroundStyleModifierV AA6IDViewV 8[ ]012EditorTabBarC0V AA022_EnvironmentKeyWritingS0V A_0W0C AA7DividerV A_0w4JumpyC0V AA08_PaddingP0V AA07DefaultgeH0V in /Users/[ ]/Library/Developer/Xcode/DerivedData/[ ]-grfjhgtlsyiobueapymobkzvfytq/Build/Products/Debug/[ ]/Contents/MacOS/[ ].debug.dylib - pointer at 0x119048408 is likely a reference to a missing weak symbol
Example crashing code:
import SwiftUI
struct MyView: View {
var body: some View {
if #available(macOS 26.0, *) {
Text("what the heck man").glassEffect()
}
}
}
When preparing SwiftUI code that uses List with .listStyle(.plain) for iOS 26, the by-default sticky section headers combined with the new translucent top-bars often causes unpleasantly overlapping text:
Two questions here:
Is there a modifier to make section headers non-sticky?
This would be helpful for cases where the translucent bar is a good fit and the section titles don't need to be sticky/pinned.
I found .listStyle(.grouped) can be an alternative in some cases, but this adds a gray background / additional padding to the section titles.
Is there a way to get a blurry material behind the section headers when they are sticking to the top bar?
This would be good for cases where the section header is important content-wise (like in the two-column example above or for a data list categorized using sections that should be always visible as a point of reference)
I found the scroll edge effects and .scrollEdgeEffectStyle(.hard, for: .top) does the trick for the top bar but doesn't affect attached sticky section headers (maybe it should?). Also I played around with .toolbarBackground(...) but this didn't do anything useful for a nav bar in my experiments.
Topic:
UI Frameworks
SubTopic:
SwiftUI
When using SwiftUI's TextEditor, the application crashes immediately on launch.
This occurs even in a brand new project with the simplest usage.
If I remove the TextEditor, the application runs normally.
Environment:
OS: macOS 15.6.1
Xcode: 16.4
SDK: macOS 14 (and also tried with macOS 15 SDK)
Steps to Reproduce:
Create a new SwiftUI macOS App project.
Replace ContentView with the following code:
import SwiftUI
struct ContentView: View {
@State private var text = "114514"
var body: some View {
TextEditor(text: $text)
}
}
Run the app.
Expected Result:
The app should display a working TextEditor.
Actual Result:
The app immediately crashes, and the debugger shows a Metal assertion error.
If I remove the TextEditor, the app works fine.
Screenshot:
Additional Notes:
This issue did not occur on macOS 14 / Xcode 15.4.
It reproduces even in an empty project.
Possibly related to SwiftUI/Metal integration on macOS 15.6.1.
這樣寫更專業、清楚,Apple 工程師能快速重現和定位問題。
如果你要用中文回報也可以,我能幫你翻譯。
Topic:
UI Frameworks
SubTopic:
SwiftUI
The following code shows that a selected button in a list gots blurred if a glass effect is applied to the list. This happens if the button style is plain or glass. It does not happen if the button style is bordered. Is this a wanted documented behavior or is this a bug?
struct ContentView: View {
@State private var items = [
"Item 1", "Item 2", "Item 3", "Item 4"]
var body: some View {
ZStack {
Image(systemName: "globe")
.resizable()
List(items, id: \.self) { item in
Button(action: {}, label: { Text(item) })
}
.padding()
.glassEffect(in: Rectangle())
}
}
}
I'm looking for a way to implement Liquid Glass effect in a Text, and I have issues.
If I want to do gradient effect in a Text, no problem, like below.
Text("Liquid Glass")
.font(Font.system(size: 30, weight: .bold))
.multilineTextAlignment(.center)
.foregroundStyle(
LinearGradient(
colors: [.blue, .mint, .green],
startPoint: .leading,
endPoint: .trailing
)
)
But I cannot make sure that I can apply the .glassEffect with .mask or .foregroundStyle. The Glass type and Shape type argument looks like not compatible with the Text shape itself.
Any solution to do this effect on Text ?
Thanks in advance for your answers.
just opened a iOS18 project in latest Xcode 26 (beta 7) and the list reordering animation is broken and jerky. on iOS 18 a change to one of the list items would smoothly move it to its correct place but in iOS 26 the items jerk around, disappear then pop up in the correct order in the list.
I am using this to filter and sort the "events"
if searchQuery.isEmpty {
return events.sort(on: selectedSortOption)
} else {
let filteredEvents = events.compactMap { event in
// Check if the event title contains the search query (case-insensitive).
let titleContainsQuery = event.title.range(of: searchQuery, options: .caseInsensitive) != nil
return titleContainsQuery ? event : nil
}
return filteredEvents.sort(on: selectedSortOption)
}
}
is there a better way for iOS 26?
Topic:
UI Frameworks
SubTopic:
SwiftUI
The following shows minimal example to reproduce the issue:
Menu {
Button("Test"){}
} label: {
Text("Menu")
} primaryAction: {
// Some action
}
primaryAction modifier will not be called when pressing the menu button/view on iOS 26 beta, long pressing it will open the menu.
Was tested on latest iOS 26 beta 8
Topic:
UI Frameworks
SubTopic:
SwiftUI
I've been experimenting with Liquid Glass quite a bit and watched all the WWDC videos. I'm trying to create a glassy segmented picker, like the one used in Camera:
however, it seems that no matter what I do there's no way to recreate a truly clear (passthrough) bubble that just warps the light underneath around the edges. Both Glass.regular and Glass.clear seem to add a blur that can not be evaded, which is counter to what clear ought to mean.
Here are my results:
I've used SwiftUI for my experiment but I went through the UIKit APIs and there doesn't seem to be anything that suggests full transparency.
Here is my test SwiftUI code:
struct GlassPicker: View {
@State private var selected: Int?
var body: some View {
ScrollView([.horizontal], showsIndicators: false) {
HStack(spacing: 0) {
ForEach(0..<20) { i in
Text("Row \(i)")
.id(i)
.padding()
}
}
.scrollTargetLayout()
}
.contentMargins(.horizontal, 161)
.scrollTargetBehavior(.viewAligned)
.scrollPosition(id: $selected, anchor: .center)
.background(.foreground.opacity(0.2))
.clipShape(.capsule)
.overlay {
DefaultGlassEffectShape()
.fill(.clear) // Removes a semi-transparent foreground fill
.frame(width: 110, height: 50)
.glassEffect(.clear)
}
}
}
Is there any way to achieve the above result or does Apple not trust us devs with more granular control over these liquid glass elements?
I've encountered a potential bug where a TextField connected to an optional value (not a string) works as expected when bound to a @State property, but won't update a @Binding property.
Here is some example code
import SwiftUI
struct ContentView: View
{
@Binding var boundValue: Double?
@State private var stateValue: Double? = 55
var body: some View
{
TextField("Bound value", value: $boundValue, format: .number)
Text("\(boundValue ?? .nan)")
TextField("State value", value: $stateValue, format: .number)
Text("\(stateValue ?? .nan)")
}
}
#Preview
{
ContentView(boundValue: .constant(42.00))
}
It's as though the optional value stored externally is preventing the value updating. Can anyone confirm whether this is intentional, or a bug?
This is in Xcode 26b6, on macOS Tahoe 26b8, but from this query it looks like the problem has existed for years.
Topic:
UI Frameworks
SubTopic:
SwiftUI