BarButtonItem target not called when initialized with uninitialized target

Originator:regexident
Number:rdar://39382273 Date Originated:12-Apr-2018 17:47
Status:Open Resolved:
Product:iOS + SDK Product Version:iOS 11.x
Classification:Other Bug Reproducible:Always
 
Summary:
Adding a UIBarButtonItem to a Controller via …

    lazy var stopButton: UIBarButtonItem = .init(
        image: UIImage(named: "Stop")?.withRenderingMode(.alwaysOriginal),
        style: .plain,
        target: self,
        action: #selector(stopRecording(_:))
    )

… causes taps to not trigger the target’s action.

Steps to Reproduce:
Open sample project and tap on bar button items

Expected Results:
Both buttons trigger the target, which increments the label’s counter

Actual Results:
Only left button works.

Version:
iOS 11.x

Notes:
I don’t think that this …

let doesntWorkButton: UIBarButtonItem = .init(
        title: "Doesn't Work",
        style: .plain,
        target: self, // This shouldn't even compile, should it?
        action: #selector(tappedButton(_:))
    )

… should compile at all. After all `self` is not fully initialized at that point.

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!