I Want to press UIBarButtonItem
programmatically in swift. I looked at the other questions asked in stackoverflow and did the same, but it didn't work.doing what i want when manually clicked but I need click programmatically.
My example code is
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let items = self.navigationItem.rightBarButtonItems
let item = items?.first
UIApplication.shared.sendAction(item.action, to: item?.target, from: nil, for: nil) // not working
_ = item.target?.perform(item.action, with: nil) // not working
let action = item.action // result is nil
let target = item.target / result is nil and item is not nil
}