ios – Downside with #accessible for UIPopoverPresentationController sourceItem with Mac Catalyst


I am engaged on an iOS/iPadOS app with an iOS deployment goal of iOS 15.0. I’m organising a view controller to be proven as a popover. To help the iPad I set the barButtonItem of the controller’s popoverPresentationController. I additionally wished to make use of the brand new sourceItem property added in iOS 16.0. This leaves me with code as follows:

let nc = UINavigationController(rootViewController: vc)
nc.modalPresentationStyle = .popover
if #accessible(iOS 16.0, *) {
    nc.popoverPresentationController?.sourceItem = btnAdd
} else {
    nc.popoverPresentationController?.barButtonItem = btnAdd

This all works simply tremendous when constructing and working for iOS/iPadOS.

I additionally wish to make my app for macOS utilizing Mac Catalyst. So I added the Mac Catalyst supported vacation spot to my goal (and eliminated the non-Catalyst Mac choice). When I attempt to construct the goal towards my Mac (working macOS 12.6), I get an error on the sourceItem line:

nc.popoverPresentationController?.sourceItem = btnAdd

The error states:

Worth of sort ‘UIPopoverPresenationController’ has no member ‘sourceItem’

Positive sufficient, the documentation exhibits sourceItem as solely being accessible for iOS 16.0+ and no others akin to a Mac Catalyst model.

I’ve tried to change the #accessible line. I’ve tried issues akin to:

if #accessible(iOS 16.0, macOS 13.0, *) {


if #accessible(iOS 16.0, macCatalyst 16.0, *) {

however none of these makes an attempt remedy the error.

What change is required to this code so it should compile underneath iOS 15, 16, and Mac Catalyst (macOS 12.3 and later)? The change would appear to require utilizing the barButtomItem line underneath Mac Catalyst and iOS 15 and solely use the sourceItem line for iOS 16.0+.

It looks like a bug that sourceItem just isn’t accessible for Mac Catalyst.


Leave a Reply

Your email address will not be published. Required fields are marked *