Hi! How can I create a toolbar animation in SwiftUI like the one shown at 16:54 in WWDC session?
Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm writing an iOS app that shares content with buddies. So my app will run in one language but the shared content will use the locale configured for the buddy.
I found this Apple documentation which suggests that locale: (Locale(identifier: is the solution.
Apple Documentation
But I can't get it to work.
Here's sample code.
struct LocalizationDemoView: View {
@State var isEnglish = true
var body: some View {
var myLocale: String { isEnglish ? "en": "de" }
VStack {
Toggle("Switch language", isOn: $isEnglish).frame(maxWidth: 200)
HStack {
Text("\(myLocale): ")
Text(String(localized: "Hello world!", locale: (Locale(identifier: myLocale)), comment: "To share"))
}
}
}
}
And here's the excerpt from the string catalog:
{
"sourceLanguage" : "en",
"strings" : {
"Hello world!" : {
"comment" : "To share",
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "🇩🇪 Moin Welt!"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "🇬🇧 Hello world!"
}
}
}
}
}
}
Has Apple reduced support for string catalogs or is my code wrong?
Xcode 16.4 compiled on MacOS 15.6.1, device iOS 18.6.2
It's related to the passByValue nature of structs. In the sample code below, I'm displaying a list of structs (and I can add instances to my list using Int.random(1..<3) to pick one of two possible predefined versions of the struct).
I also have a detail view that can modify the details of a single struct. However when I run this code, it will instead modify all the instances (ie either Sunday or Monday) in my list.
To see this behaviour, run the following code and:
tap New Trigger enough times that there are multiple of at least one of the sunday/monday triggers
tap one of the matching trigger rows
modify either the day, or the int
expected: only one of the rows will reflect the edit
actual: all the matching instances will be updated.
This suggests to me that my Sunday and Monday static instances are being passed by reference when they get added to the array. But I had thought structs were strictly pass by value. What am I missing?
thanks in advance for any wisdom,
Mike
struct ContentView: View {
@State var fetchTriggers: [FetchTrigger] = []
var body: some View {
NavigationView {
VStack {
Button("New Trigger") {
fetchTriggers.append(Int.random(in: 1..<3) == 1 ? .sunMorning : .monEvening)
}
List($fetchTriggers) { fetchTrigger in
NavigationLink(destination: FetchTriggerDetailView(fetchTrigger: fetchTrigger)
.navigationBarTitle("Back", displayMode: .inline))
{
Text(fetchTrigger.wrappedValue.description)
.padding()
}
}
}
}
}
}
struct FetchTrigger: Identifiable {
static let monEvening: FetchTrigger = .init(dayOfWeek: .monday, hour: 6)
static let sunMorning: FetchTrigger = .init(dayOfWeek: .sunday, hour: 3)
let id = UUID()
enum DayOfWeek: Int, Codable, CaseIterable, Identifiable {
var id: Int { self.rawValue }
case sunday = 1
case monday
case tuesday
var description: String {
switch self {
case .sunday: return "Sunday"
case .monday: return "Monday"
case .tuesday: return "Tuesday"
}
}
}
var dayOfWeek: DayOfWeek
var hour: Int
var description: String {
"\(dayOfWeek.description), \(hour):00"
}
}
struct FetchTriggerDetailView: View {
@Binding var fetchTrigger: FetchTrigger
var body: some View {
HStack {
Picker("", selection: $fetchTrigger.dayOfWeek) {
ForEach(FetchTrigger.DayOfWeek.allCases) { dayOfWeek in
Text(dayOfWeek.description)
.tag(dayOfWeek)
}
}
Picker("", selection: $fetchTrigger.hour) {
ForEach(1...12, id: \.self) { number in
Text("\(number)")
.tag(number)
}
}
}
}
}
Just posted this feedback regarding macOS 26 "Tahoe" (FB19853155) - please support with additional submissions if you share my view. I will miss the beautiful and individual designed icons of the past!
"macOS 26 is enforcing squicles for app icons, falling back to a grey background for 3rd party apps without a compliant AppIcon asset.
As a result many original app icons are reduced in size and hard to distinguish because they share the same background color. Although I respect Apple's strive for an iOS-like UI on Macs, a smooth transition path would be more user- and developer-friendly ... e.g. with some info.plist property to opt-out icon migration, potentially ignored by a future macOS version.
The current solution causes a bad usability, and makes the system look inconsistent as many - especially free - software will not be updated with new icon designs. Please reconsider this bad design decision!"
Feedback ID: FB19846667
When dismissing a Menu view when the device is set to dark appearance, there is a flash of lightness that is distracting and feels unnatural. This becomes an issue for apps that rely on the user interacting with Menu views often.
When using the overflow menu on a toolbar, the effect of dismissing the menu is a lot more natural and there is less flashing. I expect a similar visual effect when creating Menu views outside of a toolbar.
Has anyone found a way around this somehow?
Comparison between dismissing a menu and a toolbar overflow: https://www.youtube.com/shorts/H2gUQOwos3Y
Slowed down version of dismissing a menu with a visible light flash: https://www.youtube.com/shorts/MBCCkK-GfqY
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’ve got the new SwiftUi webview in a sheet. When I pull down the contents from the top of the page I expect it to dismiss the sheet, but it does not.
Is there a workaround or modifier I’m missing?
I've noticed that in iOS 26, Navigation Bar Items' Image Insets parameters as set in Xcode are not being read correctly. Specifically, it appears that on iOS 26 beta, negative inset numbers are being read as positive.
Feedback report FB19838333 includes a sample project demonstrating this bug.
What is the correct way to track the number of items in a relationship using SwiftData and SwiftUI?
Imagine a macOS application with a sidebar that lists Folders and Tags. An Item can belong to a Folder and have many Tags. In the sidebar, I want to show the name of the Folder or Tag along with the number of Items in it.
I feel like I'm missing something obvious within SwiftData to wire this up such that my SwiftUI views correctly updated whenever the underlying modelContext is updated.
// The basic schema
@Model final class Item {
var name = "Untitled Item"
var folder: Folder? = nil
var tags: [Tag] = []
}
@Model final class Folder {
var name = "Untitled Folder"
var items: [Item] = []
}
@Model final class Tag {
var name = "Untitled Tag"
var items: [Item] = []
}
// A SwiftUI view to show a Folder.
struct FolderRowView: View {
let folder: Folder
// Should I use an @Query here??
// @Query var items: [Item]
var body: some View {
HStack {
Text(folder.name)
Spacer()
Text(folder.items.count.formatted())
}
}
}
The above code works, once, but if I then add a new Item to that Folder, then this SwiftUI view does not update. I can make it work if I use an @Query with an #Predicate but even then I'm not quite sure how the #Predicate is supposed to be written. (And it seems excessive to have an @Query on every single row, given how many there could be.)
struct FolderView: View {
@Query private var items: [Item]
private var folder: Folder
init(folder: Folder) {
self.folder = folder
// I've read online that this needs to be captured outside the Predicate?
let identifier = folder.persistentModelID
_items = Query(filter: #Predicate { link in
// Is this syntax correct? The results seem inconsistent in my app...
if let folder = link.folder {
return folder.persistentModelID == identifier
} else {
return false
}
})
}
var body: some View {
HStack {
Text(folder.name)
Spacer()
// This mostly works.
Text(links.count.formatted())
}
}
}
As I try to integrate SwiftData and SwiftUI into a traditional macOS app with a sidebar, content view and inspector I'm finding it challenging to understand how to wire everything up.
In this particular example, tracking the count, is there a "correct" way to handle this?
Hello everybody!
TLDR: Issues with visibleItemsInvalidationHandler. Minimal code to reproduce available.
I've been working with Compositional Layout for a while now and recently I've found myself needing to implement custom animation based on scroll position of UI elements. Once I found visibleItemsInvalidationHandler it felt like the exact solution that I needed. Once I implement I've found out it doesn't quite behave as you'd expect.
To put it simply, it seems like the animations only work if your whole layout does not use .estimated nor .uniformAcrossSiblings. As soon as you use them then the animations will stop working, I've debugged it deeper and it seems like the invalidation context generated by it does not include the indexPath of the cells, which is always included in the version in which it works.
Feel free to swap the line 51 with its comment to flip between the working and failing version of it.
Playground Example
My final question therefore is... Is this the expected behavior? The documentation doesn't give any clues about such behavior and although I've tried relentlessly to find a workaround for this specific hiccup I was not successful with it.
Hi,
Is it possible to use the iOS26 Liquid Glass icon on iOS 26 (built with Icon Composer), and use the old icon on iOS18 devices? I imported the icon file into my Xcode project and it seems to use the new icon on iOS18 (and earlier) devices as well.
Thanks.
Hi everyone,
I’m encountering the following error when displaying a TextField inside a Form together with a ToolbarItem(placement: .keyboard):
Invalid frame dimension (negative or non-finite).
Environment
This issue reproduces on iPhone 12 mini (iOS 18.6).
The same code does not reproduce on iPhone 15.
I confirmed that explicitly constraining the size of the TextField or Text with .frame(width:height:) does not resolve the issue.
Minimal Reproducible Example
import SwiftUI
struct Test: View {
@State var value: Int = 0
var body: some View {
Form {
TextField("0", value: $value, format: .number)
}
.toolbar {
ToolbarItem(placement: .keyboard) {
Text("Close")
}
}
}
}
Has anyone else encountered this issue? Is this a known bug, or is there a recommended workaround for devices with smaller screen widths such as the iPhone 12 mini?
Thanks in advance for your help!
Best regards,
Naoya Ozawa
Topic:
UI Frameworks
SubTopic:
SwiftUI
Hello everyone,
Following the WWDC 2025 announcement of tvOS 26 and the introduction of the new Liquid Glass effect, Apple published a press release mentioning that Liquid Glass is "available on Apple TV 4K (2nd generation and later)".
This seems to exclude both the Apple TV HD and the 1st generation Apple TV 4K, even though both devices remain compatible with tvOS 26.
Source: Apple Newsroom ( https://www.apple.com/newsroom/2025/06/apple-tv-brings-a-beautiful-redesign-and-enhanced-home-entertainment-experience )
I’m wondering:
Will using UIGlassEffect or glassEffect(_:in:) on these older devices cause a crash?
If not, will the effect fall back to a simple blur, or render as fully transparent?
Is there an API or recommended way to detect whether the Liquid Glass effect is supported on the current device?
Thanks in advance for your insights!
FB: FB19828741
Maybe I am doing something wrong with the new LiquidGlass sidebar using iPadOS 26 Beta 7, but when using this code, in stead of the List being centered between the sidebar and the rest of the screen, the cell itself extends beneath the sidebar but the content stays clear of the sidebar, giving a weird visual effect. Not my expected behavior at least.
Any ideas? Or just a bug?
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationSplitView {
Text("Test")
} detail: {
List {
Text("ContentMargin")
}
.contentMargins(.horizontal, 100.0)
}
}
}
#Preview {
ContentView()
}
This was on iPad OS 18:
When using a custom keyboard set via UIResponder.inputView, a gap appears between the text field and the custom keyboard after rotating from portrait to landscape and back to portrait.
On a portrait screen, when switching to a custom keyboard:
The input field at the top and the custom keyboard below it appear normally, with no empty space in between.
When I rotate from portrait to landscape, a gap appears in the middle.
Topic:
UI Frameworks
SubTopic:
UIKit
Since the ios 26 beta our app is crashing when calling LoadRequest() on the wkwebview class.
The app crashes out completely when it occurs even in the debugger, I was able to get a stack trace from our Sentry crash handler. See below
It seems that calling LoadRequest from the mainthread fixes the issue but I don't understand why, theres no documentation to suggest this must be done.
Any ideas?
Below is the stack trace I got from Sentry:
WebKit
+0x0054e00
WebKit::allDataStores
WebKit
+0x0bf34f4
WebKit::NetworkProcessProxy::preconnectTo
WebKit
+0x0acef64
WebKit::WebPageProxy::preconnectTo
WebKit
+0x0b0d92c
WTF::Detail::CallableWrapper::call
WebKit
+0x0ab6cf8
WebKit::WebPageProxy::maybeInitializeSandboxExtensionHandle
WebKit
+0x0ab84dc
WebKit::WebPageProxy::loadRequestWithNavigationShared
WebKit
+0x0ab7adc
WebKit::WebPageProxy::loadRequest
WebKit
+0x05d0704
-[WKWebView loadRequest:]
Grid3iOS
+0x5240944
xamarin_dyn_objc_msgSendSuper
In App
Grid3iOS
+0x187dec4
wrapper_managed_to_native_ObjCRuntime_Messaging_NativeHandle_objc_msgSendSuper_NativeHandle_intptr_intptr_ObjCRuntime_NativeHandle
In App
Grid3iOS
+0x512fac4
Microsoft_iOS_WebKit_WKWebView_LoadRequest_Foundation_NSUrlRequest (WKWebView.g.cs:572)
The calendar widget and buttons shows a lightened / material background behind some content when the widget is in clear / tinted mode (example here: https://developer.apple.com/videos/play/wwdc2025/278?time=72).
How can this be done? I tried applying a material and glass background to a view using the .background(...) modifier, but the background is made white.
Text("Hello")
.padding()
.background {
ContainerRelativeShape()
.fill(.thinMaterial)
}
Text("Hello")
.padding()
.background {
ContainerRelativeShape()
.glassEffect()
}
Is this not supported, a bug, or am I doing something wrong?
When adding a glass effect to my UIControl:
let effectView = UIVisualEffectView()
let glassEffect = UIGlassEffect()
glassEffect.isInteractive = true
effectView.effect = glassEffect
effectView.cornerConfiguration = .capsule()
addSubview(effectView)
effectView.snp.makeConstraints { $0.edges.equalToSuperview() }
effectView.contentView.addSubview(stackView)
for subview in effectView.subviews {
subview.backgroundColor = .clear
}
self.effectView = effectView
I find that I get this visual effect:
These controls are the only view within a UICollectionViewCell. Nothing in the hierarchy of the collectionview to the control has a background color. The grey background only seems to appear when I place the glass effect.
Without the glass effect, there is no grey shading.
Topic:
UI Frameworks
SubTopic:
UIKit
The following code:
struct ContentView: View {
@State private var email = ""
var body: some View {
VStack {
TextField("email", text: $email)
.textContentType(.emailAddress)
}
}
}
does not work as expected. What I expected is to run the app and have it suggest my actual email when I click into the field. Instead what it does is display "Hide My Email" twice. Selecting the first "Hide My Email" pastes the actual text "Hide My Email" into the field, the second one brings up an iCloud sheet to select a random email.
Trying some suggestions online for .emailAddress in general not working does not change anything:
TextField("Email", text: $email)
.textFieldStyle(RoundedBorderTextFieldStyle())
.textContentType(.emailAddress)
.keyboardType(.emailAddress)
.autocorrectionDisabled()
.disableAutocorrection(true)
.textInputAutocapitalization(.never)
Topic:
UI Frameworks
SubTopic:
SwiftUI
The following is verbatim of a feedback report (FB19809442) I submitted, shared here as someone else might be interested to see it (I hate the fact that we can't see each other's feedbacks).
On iOS 16, TextKit 2 calls NSTextLayoutFragment's draw(at:in:) method once for the first paragraph, but for every other paragraph, it calls it continuously on every scroll step in the UITextView. (The first paragraph is not cached; its draw is called again when it is about to be displayed again, but then it is again called only once per its lifecycle.)
On iOS 17, the behavior is similar; the draw method gets called once for the 1st and 2nd paragraph, and for every other paragraph it again gets called continuously as a user scrolls a UITextView.
On iOS 18 (and iOS 26 beta 4), TextKit 2 calls the layout fragment's draw(at:in:) on every scroll step in the UITextView, for all paragraphs. This results in terrible performance.
TextKit 2 is promised to bring many performance benefits by utilizing the viewport - a new concept that represents the visible area of a text view, along with a small overscroll. However, having the draw method being constantly called almost negates all the performance benefits that viewport brings. Imagine what could happen if someone needs to add just a bit of logic to that draw method. FPS drops significantly and UX is terribly degraded.
I tried optimizing this by only rendering those text line fragments which are in the viewport, by using NSTextViewportLayoutController.viewportBounds and converting NSTextLineFragment.typographicBounds to the viewport-relative coordinate space (i.e. the coordinate space of the UITextView itself). However, this patch only works on iOS 18 where the draw method is called too many times, as the viewport changes. (I may have some other problems in my implementation, but I gave up on improving those, as this can't work reliably on all OS versions since the underlying framework isn't calling the method consistently.)
Is this expected? What are our options for improving performance in these areas?