You could take a look at this rather ancient sample code: https://developer.apple.com/library/archive/samplecode/TextEdit/Introduction/Intro.html, then see what has been deprecated and/or replaced since
Note that TextEdit performance is not great with large or complex files, and I have no idea if the currently-shipping TextEdit is still based on the code published in the link above or has been substantially updated.
If you want to look at newer code, try searching GitHub for "swift rich text".
Topic:
App & System Services
SubTopic:
General
Tags: