User Defined Key in NSAttributedString Not Saving

According to the documents for attributed strings, you can create any key value pair to add to the attribute dictionary for an NSAttributedString. In fact, that worked, and I could log the attributes and see my newly defined key. However, after saving the file using:

on saveFile_(sender) 
		set theData to textView's RTFDFromRange_({0, textView's textStorage()'s |length|()})
		theData's writeToFile_atomically_(openedFilePath, 1)
	end saveFile_

my user defined attribute is no longer there (as determined by opening the file and logging or looking directly at the rtfd file with TextEdit). Is there something else I need to do to make this save correctly? I don’t see anything in the docs related to this.

Ric

Well, I guess I have to answer my own question. After some searching, I found this in the Attributed String Programming Guide:

So, I looked for another way to save the data that didn’t use the RTFD format. I found that a keyed archiver would do the trick:

set theData to current application's NSKeyedArchiver's archivedDataWithRootObject_(textView's textStorage())
theData's writeToURL_atomically_(sp's |URL|(), 1)

This will write the whole contents (with any attachments) of the text view to a file, and it saves user defined attributes that you attach to your string. Using this method, I could attach anything to my link including dates, arrays, tool tips, etc. To read the data back in, I used:

set openedFilePath to op's URLs()'s objectAtIndex_(0)'s |path|()
setTheData_(current application's NSKeyedUnarchiver's unarchiveObjectWithFile_(openedFilePath))

where “op” is an open panel, and the text view’s attributed string (under the value section in IB) is bound to theData.

Ric