The following code fails since iOS14.x Is this a bug? No depreciation statements found in the SDK. Is there a workaround?
import UIKit
class ViewController: UIViewController {
private lazy var barButtonItem: UIBarButtonItem = {
UIBarButtonItem(image: .add, style: .plain, target: self, action: #selector(doSomething))
}()
override var navigationItem: UINavigationItem {
let item = super.navigationItem
item.rightBarButtonItem = barButtonItem // <- Thread 1: EXC_BAD_ACCESS (code=2, address=...)
item.title = "TestCase"
return item
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@objc private func doSomething() {
print(">>doSomething")
}
}
We are running a complex software since iOS4 and cannot simply migrate to SwiftUI.
https://stackoverflow.com/questions/64270033/override-var-navigationitem-uinavigationitem-fail-in-ios-14