Quantcast
Channel: Replace Substring with Markdown on NSTextView in Swift - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Dávid Pásztor for Replace Substring with Markdown on NSTextView in Swift

$
0
0

You should use the replaceCharacters(in:with:) method of NSText (whose subclass NSTextView is).

@IBAction func clickBold(_ sender: NSButton) {
  let range = content.selectedRange()
  let selectedText = (content.string as NSString).substring(with: range)
  content.replaceCharacters(in: range, with: "**\(selectedText)**") 
}

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>