I'm trying to support the new menu bar in iPadOS 26.
In AppDelegate I do this. I want to this to be a global command, which can work regardless of which view controller is currently visible, so I let the AppDelegate handle the selector (if there's a better way let me know).
UIMainMenuSystem.shared.setBuildConfiguration(config) { builder in
let createCollectionCommand = UIKeyCommand(
title: String(localized: "Create Collection"),
image: UIImage(systemName: "folder.badge.plus"),
action: #selector(AppDelegate.showCreateCollectionViewController),
input: "c",
modifierFlags: .control
)
builder.insertElements([createCollectionCommand], atEndOfMenu: .file)
}
This works mostly.
A problem arrises when I have multiple windows open at the same time. I need a way to determine the currently active window scene from AppDelegate to display a sheet on that window's root view controller.
There's stuff like this, but unfortunately all visible windows have activationState == .foregroundActive, so I cannot use that.
guard let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene else { return }
So, how do I do multi-window global commands? I'm basically looking for something like the "Create Playlist" command in the Music app.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Per default the menu bar on iPad includes an application menu named after your app which includes a Preferences action. That one opens the Settings app to your app settings page.
I do not really populate that with options and instead have my own settings UI accessible in my app using toolbar items.
What's the best approach to handle this with the menu bar?
I've tried replacing the default Preferences item but that only works if I do not use its shortcut, which I would like to preserve.
Another solution would be to append another Settings item for my UI, which would look weird and confusing, but seems to be the recommended way from the HIG.
Reserve the YourAppName > Settings menu item for opening your app’s page in iPadOS Settings. If your app includes its own internal preferences area, link to it with a separate menu item beneath Settings in the same group. Place any other custom app-wide configuration options in this section as well.
I take it there is no way to replace it then?
I'm using a standard UITabBarController on iPad. When first selecting any tab, the corresponding menu bar items are grayed out for this view controller. It's only when I tap any button in that view controller, like in the toolbar, that the view controller truly becomes the first responder (you can see the sidebar selection turns to gray from blue), enabling those menu bar items.
Am I doing something wrong here?
A video of the issue can be found here: https://mastodon.social/@nicoreese/114949924393554961
AppDelegate:
...
builder.insertChild(MenuController.viewModeMenu(), atStartOfMenu: .view)
class func viewModeMenu() -> UIMenu {
let listViewModeCommand = UICommand(
title: String(localized: "As List"),
image: UIImage(systemName: "list.bullet"),
action: #selector(GamesViewController.setListViewMode),
propertyList: SettingsService.ViewMode.list.rawValue
)
...
let viewModeMenu = UIMenu(
title: "",
image: nil,
identifier: .viewModeMenu,
options: .displayInline,
children: [listViewModeCommand...]
)
return viewModeMenu
}
GamesViewController:
@objc
func setListViewMode() {
updateViewMode(.list)
}
I can do this, but then the sidebar selection instantly turns gray, which looks odd and other system apps do not behave this way.
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
becomeFirstResponder()
}
override var canBecomeFirstResponder: Bool {
return true
}
let searchTab = UISearchTab { tab in
UINavigationController(rootViewController: SearchViewController())
}
searchTab.automaticallyActivatesSearch = true
class SearchViewController: UIViewController {
private let searchController = UISearchController(searchResultsController: UIViewController())
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.searchController = searchController
}
}
With this setup when I launch the app and tap the search tab, the keyboard will not appear. Switching tabs and tapping search again works from then on. Am I doing something wrong here?
Video here: https://mastodon.social/@nicoreese/114983627125286299
I would like my users to be able to switch to the search tab (in the sidebar) on iPad and immediately start typing. This is not possible. Calling becomeFirstResponder in viewDidLoad and viewWillAppear does not work. Only in viewDidAppear it does, but that comes with a significant delay between switching to the tab and the search field becoming active. Is there something else I can do?
FB19588765
let homeTab = UITab(
title: "Home",
image: UIImage(systemName: "house"),
identifier: "Home"
) { _ in
UINavigationController(rootViewController: ViewController())
}
let searchTab = UISearchTab { _ in
UINavigationController(rootViewController: SearchViewController())
}
let tabBarController = UITabBarController(tabs: [
homeTab, searchTab
])
tabBarController.mode = .tabSidebar
class SearchViewController: UIViewController {
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .systemBackground
self.title = "Search"
self.navigationItem.searchController = searchController
self.navigationItem.preferredSearchBarPlacement = .integratedCentered
searchController.becomeFirstResponder() // Does not work.
searchController.searchBar.becomeFirstResponder() // Does not work.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
searchController.searchBar.becomeFirstResponder() // Does not work.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
searchController.searchBar.becomeFirstResponder() // Works. But comes with a significant delay.
}
}
I want to display a grid of items in my widget similar to the systemLarge Shortcuts app widget. I use clipShape(.containerRelative) to get the widget corner radius, but items that do not touch a corner in any way do not get this treatment. This is even worse with the extra large widget. How can I apply the corner radius of the widget minus the padding across all items? It does not seem like the radius is exposed outside of that special shape.
I'm running a project with these settings:
Default Actor Isolation: MainActor
Approachable Concurrency: Yes
Strict Concurrency Checking: Complete (this issue does not appear on the other two modes)
I receive a warning for this very simple use case. Can I actually fix anything about this or is this a case of Core Data not being entirely ready for this?
In reference to this, there was a workaround listed in the release notes of iOS 26 beta 5 (https://forums.swift.org/t/defaultisolation-mainactor-and-core-data-background-tasks/80569/22). Does this still apply as the only fix for this?
This is a simplified sample meant to run on a background context. The issue obviously goes away if this function would just run on the MainActor, then I can remove the perform block entirely.
class DataHandler {
func createItem() async {
let context = ...
await context.perform {
let newGame = Item(context: context)
/// Main actor-isolated property 'timestamp' can not be mutated from a Sendable closure
newGame.timestamp = Date.now
// ...
}
}
}
The complete use case would be more like this:
nonisolated
struct DataHandler {
@concurrent
func saveItem() async throws {
let context = await PersistenceController.shared.container.newBackgroundContext()
try await context.perform {
let newGame = Item(context: context)
newGame.timestamp = Date.now
try context.save()
}
}
}
In didFinishLaunchingWithOptions I have this setup for getting the token to send to my server for notifications. The issue is that the delegate callback didRegisterForRemoteNotificationsWithDeviceToken gets called twice when also initializing a CKSyncEngine object.
This confuses me. Is this expected behavior? Why is the delegate callback only called twice when both are called, but not at all when only using CKSyncEngine.
See code and comments below.
/// Calling just this triggers `didRegisterForRemoteNotificationsWithDeviceToken` once.
UIApplication.shared.registerForRemoteNotifications()
/// When triggering the above function plus initializing a CKSyncEngine, `didRegisterForRemoteNotificationsWithDeviceToken` gets called twice.
/// This somewhat make sense, because CloudKit likely also registers for remote notifications itself, but why is the delegate not triggered when *only* initializing CKSyncEngine and removing the `registerForRemoteNotifications` call above?
let syncManager = SyncManager()
/// Further more, if calling `registerForRemoteNotifications` with a delay instead of directly, the delegate is only called once, as expected. For some reason, the delegate is only triggered when two entities call `registerForRemoteNotifications` at the same time?
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
UIApplication.shared.registerForRemoteNotifications()
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("didRegisterForRemoteNotificationsWithDeviceToken")
}
What's the recommended way to add a search bar in Mac Catalyst? The new NSSearchToolbarItem that was introduced in macOS 11 is not available in Catalyst. What's the alternative?
FB7828248
I have the following struct doing some simple tasks, running a network request and then saving items to Core Data.
Per Xcode 26's new default settings (onisolated(nonsending) & defaultIsolation set to MainActor), the struct and its functions run on the main actor, which works fine and I can even safely omit the context.perform call because of it, which is great.
struct DataHandler {
func importGames(withIDs ids: [Int]) async throws {
...
let context = PersistenceController.shared.container.viewContext
for game in games {
let newGame = GYGame(context: context)
newGame.id = UUID()
}
try context.save()
}
}
Now, I want to run this in a background thread to increase performance and responsiveness. So I followed this session (https://developer.apple.com/videos/play/wwdc2025/270) and believe the solution is to mark the struct as nonisolated and the function itself as @concurrent.
The function now works on a background thread, but I receive a crash: _dispatch_assert_queue_fail. This happens whether I wrap the Core Data calls with context.perform or not. Alongside that I get a few new warnings which I have no idea how to work around.
So, what am I doing wrong here? What's the correct way to solve this simple use case with Swift 6's new concurrency stuff and the default main actor isolation in Xcode 26?
Curiously enough, when setting onisolated(nonsending) to false & defaultIsolation to non isolating, mimicking the previous behavior, the function works without crashing.
nonisolated
struct DataHandler {
@concurrent
func importGames(withIDs ids: [Int]) async throws {
...
let context = await PersistenceController.shared.container.newBackgroundContext()
for game in games {
let newGame = GYGame(context: context)
newGame.id = UUID() // Main actor-isolated property 'id' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode
}
try context.save()
}
}
When creating a new project in Xcode 26, the default for defaultIsolation is MainActor.
Core Data creates classes for each entity using code gen, but now those classes are also internally marked as MainActor, which causes issues when accessing managed object from a background thread like this.
Is there a way to fix this warning or should Xcode actually mark these auto generated classes as nonisolated to make this better? Filed as FB13840800.
nonisolated
struct BackgroundDataHandler {
@concurrent
func saveItem() async throws {
let context = await PersistenceController.shared.container.newBackgroundContext()
try await context.perform {
let newGame = Item(context: context)
newGame.timestamp = Date.now // Main actor-isolated property 'timestamp' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode
try context.save()
}
}
}
Turning code gen off inside the model and creating it manually, with the nonisolated keyword, gets rid of the warning and still works fine. So I guess the auto generated class could adopt this as well?
public import Foundation
public import CoreData
public typealias ItemCoreDataClassSet = NSSet
@objc(Item)
nonisolated
public class Item: NSManagedObject {
}
For some controls it is desirable to not use the morphing transition when presenting a Menu. Instead, you might want to have the old behavior, where the menu is presented above or below the initiating view. This can be the case for any other control than toolbar items, but especially for bigger content cards, that should trigger a menu upon tapping it once. In those cases it looks weird and does not really help to keep context of what the action is doing.
Is there some way to do this right now?
In case it's not, I also filed a feedback.
FB18413055
@MainActor
class KeyboardObserver {
var token: NotificationCenter.ObservationToken!
func registerObserver(screen: UIScreen) {
let center = NotificationCenter.default
token = center.addObserver(of: screen, for: .keyboardWillShow) { keyboardState in
print("+++ Keyboard showed up!")
}
}
}
The notification is never called.
The sample code from the sessions also does not work for me.
let keyboardObserver = NotificationCenter.default.addObserver(
of: UIScreen.self
for: .keyboardWillShow
) { message in
UIView.animate(
withDuration: message.animationDuration, delay: 0, options: .flushUpdates
) {
// Use message.endFrame to animate the layout of views with the keyboard
let keyboardOverlap = view.bounds.maxY - message.endFrame.minY
bottomConstraint.constant = keyboardOverlap
}
}
@MainActor
class KeyboardObserver {
func registerObserver(screen: UIScreen) {
let center = NotificationCenter.default
let token = center.addObserver(
of: screen,
for: .keyboardWillShow
) { keyboardState in
let startFrame = keyboardState.startFrame
let endFrame = keyboardState.endFrame
self.keyboardWillShow(startFrame: startFrame, endFrame: endFrame)
}
}
func keyboardWillShow(startFrame: CGRect, endFrame: CGRect) {}
}
Was it always so tricky to ignore the bottom safe area? Seems like iOS 26 makes this much harder.
I've tried many variations of ignoresSafeArea, safeAreaInset, safeAreaBar, etc. Nothing seems to work. As soon as I add padding, the bottom safe area crashes the party.
This is what I want to achieve:
This is what I get right now:
struct ContentView: View {
var body: some View {
List {
Text("Content")
}
.overlay(alignment: .bottom) {
content
}
}
var content: some View {
VStack {
Text("Custom Container")
}
.frame(maxWidth: .infinity)
.frame(height: 400)
.background(Color.gray, in: .rect(corners: .concentric, isUniform: true))
.padding(15)
}
}
I want the gray view to have concentric corners with the device border. That works. Then I want the blue rectangle to have concentric corners with the gray view. That does not work. Instead the blue rectangle is also concentric with the device border. Once I add other content like a Text element, the corner radius breaks.
How can I make this work? .containerShape does not take a ConcentricContainerShape.
struct ContentView: View {
var body: some View {
List {
Text("Content")
}
.overlay(alignment: .bottom) {
content
}
.ignoresSafeArea(.all, edges: .bottom)
}
var content: some View {
VStack(alignment: .leading) {
Rectangle()
.foregroundStyle(.blue)
.frame(width: 100, height: 100)
.clipShape(.rect(corners: .concentric, isUniform: true))
Text("Custom Container")
}
.padding(20)
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.gray, in: .rect(corners: .concentric, isUniform: true))
.padding(15)
}
}