Skip navigation.
 
mlRe: Attributed strings and custom attributes
FROM : Jeremy Dronfield
DATE : Thu Jul 20 19:24:08 2006

On 20 Jul 2006, at 5:53 pm, Douglas Davidson wrote:
>
> On Jul 20, 2006, at 5:56 AM, Jeremy Dronfield wrote:
>

>> Has anyone come up with a way of getting custom attributes on an 
>> attributed string to save?
>>
>> I'm using -[NSAttributedString 
>> RTFDFileWrapperFromRange:documentAttributes:] to save the contents 
>> of a text view containing text with custom attributes. (The value 
>> of the custom attribute type is an NSDictionary containing 
>> metadata. The metadata is related to an NSTextAttachment which is 
>> added to the same piece of text as the custom attribute.)  When 
>> the file is reloaded into the text view, my custom attributes have 
>> disappeared. A trawl of the archives suggests that this has been a 
>> perennial problem, but offers no solutions other than archiving, 
>> which is of no use to me in this situation.
>>

>
> This is a difficult problem, and one that has been on our minds. 
> It is technically possible to include custom information within 
> RTF, but it is not easy to provide a generalized facility for doing 
> so.  For now, if you wish to have RTFD-persistent information 
> associated with attachments, you will need to include it by some 
> means or other with the contents of the attached files.
>
> For example, you could write out a container file of some sort that 
> includes both your metadata and the actual contents of the original 
> attached file, and then split out the two parts after reading in 
> the document.  Alternatively, it would also be possible to add 
> additional files to the RTFD file wrapper, alongside the attached 
> files, but you would need to arrange a mapping between the attached 
> files and the metadata files.  As another alternative, you could 
> add a single additional attached file at the end of the document, 
> representing a dictionary of dictionaries mapping from attached 
> files to metadata dictionaries.


Thanks, that's given something to think about. At first glance, the 
container file sounds most promising. As a temporary (I hope) kludge, 
I've fallen back on using NSLinkAttributeName, with a custom URL 
signature which I parse in -clickedOnLink:

Jeremy

Related mailsAuthorDate
mlAttributed strings and custom attributes Jeremy Dronfield Jul 20, 14:56
mlRe: Attributed strings and custom attributes Douglas Davidson Jul 20, 18:53
mlRe: Attributed strings and custom attributes Jeremy Dronfield Jul 20, 19:24