UIPageViewController: possible bug in dataSource/delegate deallocation detection

Originator:indiekiduk
Number:rdar://FB7683976 Date Originated:1/5/2020
Status:Open Resolved:No
Product:UIKit Product Version:iOS 13.4.1
Classification:Bug Reproducible:Always
 
I noticed that UIPageViewController dataSource and delegate properties have handy deallocation detection so that if these weak properties get zeroed then the UI updates to the new behaviour, e.g. without a datasource you are prevented from scrolling pages. This is achieved by setDataSource/setDelegate called with nil when these objects are dealloced. In my experiments I noticed a possible bug: The deallocation detection calling nil on these setters only works for one of datasource or delegate but not both.

After deeper investigation it look like there is a possible copy/paste bug within setDataSource and setDelegate custom setters. My theory is that in both setters the  _UIWeakHelper object that is created and associated to the delegate and dataSource objects using objc_setAssociatedObject is being set to the same key. This would mean the object doing the deallocation detection is being overwritten and the result is only one of the setters is set to nil, which matches the behaviour I'm seeing hence why I am submitting this bug report.

I'm attaching a sample project to demonstrate the problem.

Launch it on iPhone 8 Simulator in Landscape.
Tap the "Item" bar button item to push on a Master table.
Tap + to add a few records.
Tap a cell to select it.
Drag up or down on the detail label to notice the pages moving.
Tap back on the Master nav.

What I expect:
Drag up/down on detail should be disabled.

What happens:
Dragging is still possible. The dataSource was not set to nil when the Master deallocated. Debug by enabling a break points in PageViewController.m setDelegate and setDatasource. You'll notice when tapping back only setDelegate:nil is called, setDataSource:nil isn't called.

Xcode 11.4.1 
iOS Simulator 13.4.1
UIKit 3920.26.113

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!