Question: I have a Cocoa app with an `NSTextView` control which holds its text in an `NSAttributedString` (actually I believe it's a `NSMutableAttributedString`). I can easily set and modify different text attributes (such as font, underline, etc.) on different character ranges inside that string.

However, I want to set a part of the text as **hidden** (similar to the effect of the CSS attribute `display: none`). When an external event occurs (say a button clicked), I want to unhide or hide that specific range of characters.

Is there anyway to do this with `NSAttributedString`?

Answer: 
The supported attributes for NSAttributedString are listed in AppKit's NSAttributedString.h header. There's no key like 'hidden' or 'visible'. The attributes (styles) are not derived from html and cannot express all css features.

Nevertheless, to hide a range of characters you can set the foreground color to transparent:

```
NSMutableAttributedString* myString;

[myString addAttribute:NSForegroundColorAttributeName
                 value:[NSColor clearColor]
                 range:NSMakeRange(0, 10)];

```
As far as I know there are no invisible type attributes for NSAttributedString, however you could create a subclass of NSAttributedString (or the Mutable version, but that might not be necessary) that overrides the drawInRect: to avoid drawing the portion of the text that has your attribute.

But this could be a little messy.