Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

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.

All subtopics
Posts under UI Frameworks topic

Post

Replies

Boosts

Views

Activity

Resolving AppIntent in the app from a widget...
Is anyone familiar with AppIntents and their usage? I have an AppIntent defined in my widget extension. I have the same AppIntent defined in the app marked as ForegroundContinuableIntent. If I add the intent on a SwiftUI button and tap the Button it correctly resolves the app's version of the intent and performs that intent. However, what I really want to do is perform the AppIntent manually as the timeline updates but not more often than every hour (i.e. >= 1 hour). It's easy enough to handle the timing in the timeline. However, I do not know how to resolve the intent such that it calls the app's version of the intent (i.e. the same way that a Button does). If I just call perform it will run the version in the widget extension. The end goal is to minimally / periodically sync with the app. Thanks in advance for any help / advice on this.
Topic: UI Frameworks SubTopic: SwiftUI
3
0
96
1d
ViewThatFits and Text Truncation
I'm using ViewThatFits to handle different screen sizes as well as the orientation of the phone. Essentially, I have a smaller view that should only be used in portrait mode on the phone and a larger view that should be used in every other instance. The issue is that both of those views have a Text view that is bound to a String within a SwiftData model. If the String is too long the ViewThatFits considers that when choosing the appropriate subview. This results in a list of items where most items use one view while one or more may use the other view. It would be great if there was a modifier that could be applied to the Text view that resulted in the ViewThatFits ignoring it when determining the appropriate subview. Until such a modifier is available, has anyone come up with creative ways around this?
1
0
23
1d
Detect when app window is being moved
Is there a way to detect when your apps (or any app I guess) is being moved by the user clicking and dragging the main window around the desktop at all? I'm trying to find out if there's a way I can find out if a window is being clicked and dragged and whether there's certain triggers to the movement a little bit like shaking an iPhone with Shake to Undo. Thanks
0
0
17
1d
Can't display image in SwiftUI
I'm trying to display my apps icon within my app and it's not working. It displays a blank space instead and I don't understand why this is happening. I tried creating a new image (just a normal image, not an 'App Icon' image set) and have this code: Image("AppIcon") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 48) .cornerRadius(10) .overlay( RoundedRectangle(cornerRadius: 10) .stroke(Color.black.opacity(0.1), lineWidth: 1) ) For some strange reason it's not displaying that either. The image name is correct. It's showing a blank white box.
2
0
37
1d
encounter memory leak for SVG image
I have a memory leak for SVG image that located in Assets.xcassets file when using SwiftUI Image, but when I use UIImage then convert it to SwiftUI Image the issue is not found. import SwiftUI struct ContentView: View { var body: some View { NavigationStack { VStack { NavigationLink("Show", destination: SecondView()) } .padding() } } } struct SecondView: View { @Environment(\.dismiss) var dismiss var body: some View { NavigationStack { VStack { IM.svgImage .resizable() .scaledToFit() .frame(width: 200, height: 200) Button("Dismiss") { dismiss() } } } } } enum IM { static let testImage: Image = "test_image".image static let svgImage: Image = "svgImage".image } extension String { var image: Image { Image(self) // Memory leak } var imageFromUIImage: Image { guard let uiImage = UIImage(named: self) else { return Image(self) } return Image(uiImage: uiImage) // No Memory leak } } Environment that produces the issue: Xcode: 16.2 Simulator: iPhone 15 Pro (iOS 17.5)
1
0
24
1d
@Transient update doesn't propagate to view
When I update a variable inside my model that is marked @Transient, my view does not update with this change. Is this normal? If I update a non-transient variable inside the model at the same time that I update the transient one, then both changes are propagated to my view. Here is an example of the model: @Model public class WaterData { public var target: Double = 3000 @Transient public var samples: [HKQuantitySample] = [] } Updating samples only does not propagate to my view.
7
8
2.6k
1d
SwiftUI lifecycle / CarPlay / data model
Is there a way to share a SwiftUI App's @Observable model into a CPTemplateApplicationSceneDelegate ? Is there an incantation to go from the UIApplicationDelegate via @UIApplicationDelegateAdaptor to the UISceneDelegate for CarPlay via a userInfo? I can't seem to figure it out. Otherwise I have to use a shared global, and I'd prefer not to have to do it this way. Any ideas? Thanks!
2
0
43
1d
PDF in WebView
Dear all, Is it possible to replace the default PDF background colour the 50% grey to any other colour while using the new WebView? Using the standard .background method on WebView does not appear to have any effect: WebView(pdfWebpage) .background(Color.blue) // no effect on the background of the PDF Thanks!
1
0
38
1d
Xcode 26 - New Swift 6.2 Concurrency Sendable Closure Problems
I'm running into a seemingly unsolvable compile problem with the new Xcode 26 and Swift 6.2. Here's the issue. I've got this code that was working before: NSAnimationContext.runAnimationGroup({(context) -> Void in context.duration = animated ? 0.5 : 0 clipView.animator().setBoundsOrigin(p) }, completionHandler: { self.endIgnoreFrameChangeEvents() }) It's very simple. The clipView is a scrollView.contentView, and "animated" is a bool, and p is an NSPoint It captures those things, scrolls the clip view (animating if needed) to the point, and then calls a method in self to signal that the animation has completed. I'm getting this error: Call to main actor-isolated instance method 'endIgnoreFrameChangeEvents()' in a synchronous nonisolated context So, I don't understand why so many of my callbacks are getting this error now, when they worked before, but it is easy to solve. There's also an async variation of runAnimationGroup. So let's use that instead: Task { await NSAnimationContext.runAnimationGroup({(context) -> Void in context.duration = animated ? 0.5 : 0 clipView.animator().setBoundsOrigin(p) }) self.endIgnoreFrameChangeEvents() } So, when I do this, then I get a new error. Now it doesn't like the first enclosure. Which it was perfectly happy with before. Here's the error: Sending value of non-Sendable type '(NSAnimationContext) -> Void' risks causing data races Here are the various overloaded definitions of runAnimationGroup: open class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void, completionHandler: (@Sendable () -> Void)? = nil) @available(macOS 10.7, *) open class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void) async @available(macOS 10.12, *) open class func runAnimationGroup(_ changes: (NSAnimationContext) -> Void) The middle one is the one that I'm trying to use. The closure in this overload isn't marked sendable. But, lets try making it sendable now to appease the compiler, since that seems to be what the error is asking for: Task { await NSAnimationContext.runAnimationGroup({ @Sendable (context) -> Void in context.duration = animated ? 0.5 : 0 clipView.animator().setBoundsOrigin(p) }) self.endIgnoreFrameChangeEvents() } So now I get errors in the closure itself. There are 2 errors, only one of which is easy to get rid of. Call to main actor-isolated instance method 'animator()' in a synchronous nonisolated context Call to main actor-isolated instance method 'setBoundsOrigin' in a synchronous nonisolated context So I can get rid of that first error by capturing clipView.animator() outside of the closure and capturing the animator. But the second error, calling setBoundsOrigin(p) - I can't move that outside of the closure, because that is the thing I am animating! Further, any property you're going to me animating in runAnimationGroup is going to be isolated to the main actor. So now my code looks like this, and I'm stuck with this last error I can't eliminate: let animator = clipView.animator() Task { await NSAnimationContext.runAnimationGroup({ @Sendable (context) -> Void in context.duration = animated ? 0.5 : 0 animator.setBoundsOrigin(p) }) self.endIgnoreFrameChangeEvents() } Call to main actor-isolated instance method 'setBoundsOrigin' in a synchronous nonisolated context There's something that I am not understanding here that has changed about how it is treating closures. This whole thing is running synchronously on the main thread anyway, isn't it? It's being called from a MainActor context in one of my NSViews. I would expect the closure in runAnimationGroup would need to be isolated to the main actor, anyway, since any animatable property is going to be marked MainActor. How do I accomplish what I am trying to do here? One last note: There were some new settings introduced at WWDC that supposedly make this stuff simpler - "Approchable Concurrency". In this example, I didn't have that turned on. Turning it on and setting the default to MainActor does not seem to have solved this problem. (All it does is cause hundreds of new concurrency errors in other parts of my code that weren't there before!) This is the last new error in my code (without those settings), but I can't see any way around this one. It's basically the same error as the others I was getting (in the callback closures), except with those I could eliminate the closures by changing APIs.
5
0
120
1d
Face ID authentication via LAContext may not always result in App lifecycle notifications
When a user swipes up to see the app switcher, I put a blocking view over my app so the data inside cannot be seen if you flick through the app switcher. I do this by receive notifications(UIApplicationDidBecomeActiveNotification, UIApplicationWillResignActiveNotification) But on my iPhone 16 Pro, iOS 18.4.1 test device, Face ID authentication via LAContext may not always result in App lifecycle notifications.This caused my blocking view not to be removed. any ideas about the notification changes caused by Biometric authentication?
3
0
48
2d
Xcode26 build app with iOS26, UITabBarController set CustomTabBar issue
Our project using UITabBarController and set a custom tabbar using below code: let customTabBar = CustomTabBar(with: dataSource) setValue(customTabBar, forKey: "tabBar") But when using Xcode 26 build app in iOS 26, the tabbar does not show: above code works well in iOS 18: below is the demo code: AppDelegate.swift: import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { let window: UIWindow = UIWindow() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { window.rootViewController = TabBarViewController() window.makeKeyAndVisible() return true } } CustomTabBar.swift: import UIKit class CustomTabBar: UITabBar { class TabBarModel { let title: String let icon: UIImage? init(title: String, icon: UIImage?) { self.title = title self.icon = icon } } class TabBarItemView: UIView { lazy var titleLabel: UILabel = { let titleLabel = UILabel() titleLabel.translatesAutoresizingMaskIntoConstraints = false titleLabel.font = .systemFont(ofSize: 14) titleLabel.textColor = .black titleLabel.textAlignment = .center return titleLabel }() lazy var iconView: UIImageView = { let iconView = UIImageView() iconView.translatesAutoresizingMaskIntoConstraints = false iconView.contentMode = .center return iconView }() private var model: TabBarModel init(model: TabBarModel) { self.model = model super.init(frame: .zero) setupSubViews() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func setupSubViews() { addSubview(iconView) iconView.topAnchor.constraint(equalTo: topAnchor).isActive = true iconView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true iconView.widthAnchor.constraint(equalToConstant: 34).isActive = true iconView.heightAnchor.constraint(equalToConstant: 34).isActive = true iconView.image = model.icon addSubview(titleLabel) titleLabel.topAnchor.constraint(equalTo: iconView.bottomAnchor).isActive = true titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true titleLabel.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true titleLabel.heightAnchor.constraint(equalToConstant: 16).isActive = true titleLabel.text = model.title } } private var dataSource: [TabBarModel] init(with dataSource: [TabBarModel]) { self.dataSource = dataSource super.init(frame: .zero) setupTabBars() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func sizeThatFits(_ size: CGSize) -> CGSize { var sizeThatFits = super.sizeThatFits(size) let safeAreaBottomHeight: CGFloat = safeAreaInsets.bottom sizeThatFits.height = 52 + safeAreaBottomHeight return sizeThatFits } private func setupTabBars() { backgroundColor = .orange let multiplier = 1.0 / Double(dataSource.count) var lastItemView: TabBarItemView? for model in dataSource { let tabBarItemView = TabBarItemView(model: model) addSubview(tabBarItemView) tabBarItemView.translatesAutoresizingMaskIntoConstraints = false tabBarItemView.topAnchor.constraint(equalTo: topAnchor).isActive = true tabBarItemView.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true if let lastItemView = lastItemView { tabBarItemView.leadingAnchor.constraint(equalTo: lastItemView.trailingAnchor).isActive = true } else { tabBarItemView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true } tabBarItemView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: multiplier).isActive = true lastItemView = tabBarItemView } } } TabBarViewController.swift: import UIKit class NavigationController: UINavigationController { override func viewDidLoad() { super.viewDidLoad() } } class HomeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .red navigationItem.title = "Home" } } class PhoneViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .purple navigationItem.title = "Phone" } } class PhotoViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .yellow navigationItem.title = "Photo" } } class SettingViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .green navigationItem.title = "Setting" } } class TabBarViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() let homeVC = HomeViewController() let homeNav = NavigationController(rootViewController: homeVC) let phoneVC = PhoneViewController() let phoneNav = NavigationController(rootViewController: phoneVC) let photoVC = PhotoViewController() let photoNav = NavigationController(rootViewController: photoVC) let settingVC = SettingViewController() let settingNav = NavigationController(rootViewController: settingVC) viewControllers = [homeNav, phoneNav, photoNav, settingNav] let dataSource = [ CustomTabBar.TabBarModel(title: "Home", icon: UIImage(systemName: "house")), CustomTabBar.TabBarModel(title: "Phone", icon: UIImage(systemName: "phone")), CustomTabBar.TabBarModel(title: "Photo", icon: UIImage(systemName: "photo")), CustomTabBar.TabBarModel(title: "Setting", icon: UIImage(systemName: "gear")) ] let customTabBar = CustomTabBar(with: dataSource) setValue(customTabBar, forKey: "tabBar") } } And I have post a feedback in Feedback Assistant(id: FB18141909), the demo project code can be found there. How are we going to solve this problem? Thank you.
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
45
2d
Old style tab bar
I am maintaining an enterprise iOS app that does a lot of customization to the tab bar's colors based on the organization signed into the app. Is there a way to revert back to the old style full bottom tab bar rather than the new iOS 26 floating version? I know last year in iPad OS you could force the bottom tab using traitOverrides, but I'm not seeing a similar option for this. If anyone has any ideas it would be greatly appreciated.
Topic: UI Frameworks SubTopic: UIKit Tags:
4
1
106
2d
.roundedCorners instead of .cornerRadius(?)
In WWDC 25's session Get to Know the Design system, Maria mentions that corner radius should match it's parent view or the iPhone's corners if its the outermost view. Rather than trying to figure out what number to pass into .cornerRadius(15), why not have a .roundedCorner modifier and have the system do this geometry work? See my feedback also FB17947241
Topic: UI Frameworks SubTopic: SwiftUI
2
2
71
2d