Convert NSAttributedString into Data for storage
I have a UITextView with attributed text and allowsEditingTextAttributes set to true . I'm trying to convert the attributed string into a Data object, using the following code: let text = self.textView.attributedText let data = try text.data(from: NSMakeRange(0, text.length), documentAttributes: [:]) However, this is throwing the following error: Error Domain=NSCocoaErrorDomain Code=66062 "(null)" Any ideas what this error means or what could cause this? I'm on the latest Xcode and iOS. Thanks. You need to specify what kind of document data you would like to convert your attributed string to: