I want to add an UIMenu with conditional menu children to a UIButton's menu on iOS14, but the replacingChildren does not work.
self.button.menu = UIMenu( options: .displayInline, children:[
UIAction(title:"Action 1"){_ in},
UIAction(title:"Action 2"){_ in}
])
//Try to update menu's children but it does not work
self.button.menu = self.button.menu?.replacingChildren([
UIAction(title:"Action 3"){_ in},
UIAction(title:"Action 4"){_ in}
])
The menu does not change. I need to create a completely new instance of UIMenu with new children and assign it to self.button.menu. How to use replacingChildren or any mistake?