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()
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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.
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 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)
}
}
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()
}
}
}
Filed as FB20766506
I have a very simple use case for a rectangular widget on the iPhone lock screen: One Text element which should fill as much space as possible. However, it only ever does 2 per default and then eclipses the rest of the string.
Three separate Text elements work fine, so does a fixedSize modifier hack (with that even four lines are possible!). Am I completely misunderstanding something or why is this not possible per default? Other apps' widgets like Health do it as well.
My attempt (background added for emphasis)
Health app widget
var body: some View {
VStack(alignment: .leading) {
/// This should span three lines, but only spans 2 which eclipsed text.
Text("This is a very long text which should span multiple lines.")
// .fixedSize(horizontal: false, vertical: true) /// Using this fixes it as well, but that does not seem like a good default solution.
/// Three separate `Text` elements work fine.
// Text("This is a very long")
// Text("text which should")
// Text("span multiple lines.")
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.background(Color.black) /// Added for emphasis of the widget frame
}
When composing tabs like this and selecting them in the sidebar, only the group's view controller is ever displayed, even when selecting the individual first and second tabs. Their view controllers are just ignored. Am I immensely stupid here or is this a bug in iPadOS 26 beta 3?
// First tab
let firstTab = UITab(
title: "First",
image: UIImage(systemName: "heart"),
identifier: "hello"
) { _ in
UINavigationController(rootViewController: ViewController())
}
// Second tab
let secondTab = UITab(
title: "Second",
image: UIImage(systemName: "heart"),
identifier: "hello2"
) { _ in
UIViewController()
}
// Tab group
let tabGroup = UITabGroup(
title: "Stuff",
image: nil,
identifier: "stuff",
children: [firstTab, secondTab]
) { _ in
ViewController()
}
let tbc = UITabBarController(tabs: [tabGroup])
tbc.mode = .tabSidebar
Topic:
UI Frameworks
SubTopic:
UIKit
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?
@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)
}
}
If you use UISceneDelegate's scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) to handle deep links (such as tapping a widget) you might run into an issue where this callback is called twice in the majority of cases.
If you push a view controller in response to this, you might end up with two pushed view controllers, if you do not mitigate this. This is exclusively an issue in iOS 26.0 and works as expected on iOS 18.
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
/// Add any widget to the home screen that uses the widgetURL modifier and tap them. Most of the time, openURLContexts() will get called twice.
/// If you run this project on iOS 18, it's *always* called once as expected.
print("openURLContexts \(URLContexts)")
}
Filed as FB20301454
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")
}
How can I use the same translucent selection style in the sidebar that apps like Finder, Music, and Podcasts use? By default Mac Catalyst apps seem to use the tint color for the selection, which looks out of place with the system apps.
I use UICollectionLayoutListConfiguration by the way.
At WWDC the scroll edge effect was presented as a variable blur combined with a soft gradient.
Since beta 4 the bottom scroll edge effect has no blur, the top bar sometimes has, but sometimes does not. Even in my own app I have two views with totally different results. This was not changed back in beta 5, so I assume this is not a bug but an intended change.
It's hard to design for such a moving target. Especially the missing bottom blur looks bad in a lot of places in my app and I'm debating not shipping the new design if this does not get resolved.
Is there any guidance how this effect is supposed to look now? At this point it just seems random and there's no way adjust the way it looks.
Phone: Top blur, bottom no blur
Settings: Top blur, bottom no blur
Notes: No blur at all
Music: No blur at all
My own app: No top blur
My own app: Top blur