If you really don't want to allow any actions, why do you check for each of them specifically? Just return false in your method. Otherwise, you can place a breakpoint and see what you're getting called with for "action" and add another validation for it
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
print("BlahTextView::canPerformAction: \(action)")
return false
}
And the result, with the 2 you want removed highlighted:
BlahTextView::canPerformAction: cut:
BlahTextView::canPerformAction: copy:
BlahTextView::canPerformAction: select:
BlahTextView::canPerformAction: selectAll:
BlahTextView::canPerformAction: paste:
BlahTextView::canPerformAction: delete:
BlahTextView::canPerformAction: _promptForReplace:
BlahTextView::canPerformAction: _transliterateChinese:
BlahTextView::canPerformAction: _showTextStyleOptions:
BlahTextView::canPerformAction: _lookup:
BlahTextView::canPerformAction: _define:
BlahTextView::canPerformAction: _addShortcut:
BlahTextView::canPerformAction: _accessibilitySpeak:
BlahTextView::canPerformAction: _accessibilitySpeakLanguageSelection:
BlahTextView::canPerformAction: _accessibilityPauseSpeaking:
BlahTextView::canPerformAction: _share:
BlahTextView::canPerformAction: makeTextWritingDirectionRightToLeft:
BlahTextView::canPerformAction: makeTextWritingDirectionLeftToRight:
And then you can do:
override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(copy(_:)) ||
action == #selector(paste(_:)) ||
action == #selector(select(_:)) ||
action == #selector(selectAll(_:)) ||
action == #selector(cut(_:)) ||
action == Selector(("_lookup:")) ||
action == Selector(("_share:")) ||
action == Selector(("_define:"))
{
return false
}
return super.canPerformAction(action, withSender: sender)
}
The alternate syntax is required because those methods are not publicly declared and you'll get a compiler error if you use #selector(share(:)) for example.
for lookup - please use ((_define:)) Thanks.