NSTextView ignore specific char input

I have a NSTextView, and I want to forbid users from typing in some specific character like "K", (when "K" is pressed,ignore the input, and don't change the underlying textStorage). is there a way I can do it? appreciate very much

Answered by zcius in 722953022

figure it out   

public func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: String?) -> Bool { if replacementString == "K" { return false }

return true

}

Accepted Answer

figure it out   

public func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: String?) -> Bool { if replacementString == "K" { return false }

return true

}

NSTextView ignore specific char input
 
 
Q