> It turns out to be pretty easy for me to add my 'match' objects to the the 
> text storages. I just needed to make the match class (TPDocumentMatch) a 
> subclass of NSTextAttachment. Then once I've collected all my matches for a 
> given file, I do
> 
>  [storage beginEditing];
>  for (TPDocumentMatch *match in resultDoc.matches) {
>    // attach the resultDoc to the text
>    [storage addAttribute:NSAttachmentAttributeName value:match 
> range:match.range];    
>    NSLog(@"%@", [doc textStorage]);
>  }  
>  [storage endEditing];
>  NSLog(@"%@", [doc textStorage]);
> 
> The problem I have is that the attachment is present according to the NSLog 
> within the loop, but by the time we get to the NSLog outside the loop, the 
> attachment has vanished. 

Your attachments (TPDocumentMatch objects) are being removed because 
NSAttachmentAttributeName is only a valid attribute when applied to 
NSAttachmentCharacter. See:

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSMutableAttributedString_AppKitAdditions/Reference/Reference.html#//apple_ref/occ/instm/NSMutableAttributedString/fixAttachmentAttributeInRange:

This makes sense, because your match information isn't really an attachment 
(which is distinct visible content the user could interact with like an image, 
token field cell, etc). You're just keeping track of ancillary data that 
happens to be applied to some text.

Instead, you'll want to use a custom attribute/name, eg:

        NSString* TPDocumentMatchAttributeName = @"TPDocumentMatchAttribute";
        ...
        [storage addAttribute:TPDocumentMatchAttributeName value:match 
range:match.range];

~Martin


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to