I'm trying to make this function inside a VC into a function within an extension (because I need to access it in multiple VC's so I'm trying to return the attributedStringWithRtf so i can use it elsewhere.
func populateTextViewWithCurrentScene() {
let fileURL = getFileURL()
do {
let attributedStringWithRtf:NSAttributedString = try NSAttributedString(
url: fileURL,
options: [.documentType: NSAttributedString.DocumentType.rtf],
documentAttributes: nil
)
self.textViewOutlet.attributedText = attributedStringWithRtf
}
catch {
print("failed to populate text view with current scene with error: \(error)")
}
}
So far, I've tried this, following the guide here How could I create a function with a completion handler in Swift? and I've also tried a version declaring a var before the function. The error I'm getting on the below is Cannot call value of non-function type 'NSAttributedString'.
I know there are quite a few questions about this sort of thing but a lot are for old versions of Swift
func populateTextViewWithCurrentScene(rtfString: NSAttributedString) -> Void {
let fileURL = getFileURL()
do {
let rtfString:NSAttributedString = try NSAttributedString(
url: fileURL,
options: [.documentType: NSAttributedString.DocumentType.rtf],
documentAttributes: nil
)
}
catch {
print("failed to populate text view with current scene with error: \(error)")
}
rtfString()
}