• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dynamic modification of text search results
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamic modification of text search results


  • Subject: Re: Dynamic modification of text search results
  • From: Martin Wierschin <email@hidden>
  • Date: Wed, 04 Jul 2012 14:43:23 -0700

> 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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Dynamic modification of text search results
      • From: Ross Carter <email@hidden>
References: 
 >Dynamic modification of text search results (From: Martin Hewitson <email@hidden>)
 >Re: Dynamic modification of text search results (From: Marco Tabini <email@hidden>)
 >Re: Dynamic modification of text search results (From: Martin Hewitson <email@hidden>)
 >Re: Dynamic modification of text search results (From: Marco Tabini <email@hidden>)
 >Re: Dynamic modification of text search results (From: Martin Hewitson <email@hidden>)

  • Prev by Date: Re: Stupid block syntax!
  • Next by Date: Re: Stupid block syntax!
  • Previous by thread: Re: Dynamic modification of text search results
  • Next by thread: Re: Dynamic modification of text search results
  • Index(es):
    • Date
    • Thread