NSTextStorage Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.0 and later. |
| Declared in | NSTextStorage.h NSTextStorageScripting.h |
| Companion guides | |
Overview
NSTextStorage is a semiconcrete subclass of NSMutableAttributedString that manages a set of client NSLayoutManager objects, notifying them of any changes to its characters or attributes so that they can relay and redisplay the text as needed. NSTextStorage defines the fundamental storage mechanism of the Application Kit’s extended text-handling system.
Tasks
Managing NSLayoutManager Objects
Handling Text Edited Messages
-
– edited:range:changeInLength: -
– ensureAttributesAreFixedInRange: -
– fixesAttributesLazily -
– invalidateAttributesInRange: -
– processEditing
Determining the Nature of Changes
Determining the Extent of Changes
Setting the Delegate
Getting and Setting Scriptable Properties
Instance Methods
addLayoutManager:
Adds a layout manager to the receiver’s set of layout managers.
Parameters
- aLayoutManager
The layout manager to add.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextStorage.hattributeRuns
Returns an array of the receiver’s attribute runs.
Return Value
An array of the receiver’s attribute runs.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hchangeInLength
Returns the difference between the current length of the edited range and its length before editing began.
Return Value
The difference between the current length of the edited range and its length before editing began. That is, before the receiver was sent the first beginEditing message or a single edited:range:changeInLength: message.
Discussion
This difference is accumulated with each invocation of edited:range:changeInLength:, until a final message processes the changes.
The receiver’s delegate and layout managers can use this information to determine the nature of edits in their respective notification methods.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextStorage.hcharacters
Returns the receiver’s text as an array of characters.
Special Considerations
Do not use this method unless you are dealing directly with scriptability. For indexed access to characters, use NSAttributedString’s length method to access the string, and NSString’s characterAtIndex: method to access the individual characters.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hdelegate
Returns the receiver’s delegate.
Return Value
The receiver's delegate.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextStorage.hedited:range:changeInLength:
Tracks changes made to the receiver, allowing the text storage to record the full extent of changes made.
Parameters
- mask
A mask specifying the nature of the changes. The value is made by combining with the C bitwise OR operator the options described in
“Change notifications”.- oldRange
The extent of characters affected before the change took place.
- lengthChange
The number of characters added to or removed from oldRange. If no characters where edited as noted by mask, its value is irrelevant and undefined. For example, when replacing “The” with “Several” in the string “The files couldn’t be saved”, oldRange is {0, 3} and lengthChange is 4.
Discussion
This method invokes processEditing if there are no outstanding beginEditing calls. NSTextStorage invokes this method automatically each time it makes a change to its attributed string. Subclasses that override or add methods that alter their attributed strings directly should invoke this method after making those changes; otherwise you should not invoke this method. The information accumulated with this method is then used in an invocation of processEditing to report the affected portion of the receiver.
The methods for querying changes, editedRange and changeInLength, indicate the extent of characters affected after the change. This method expects the characters before the change because that information is readily available as the argument to whatever method performs the change (such as replaceCharactersInRange:withString:).
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.heditedMask
Returns the kinds of edits pending for the receiver
Return Value
A mask describing the kinds of edits pending for the receiver.
Discussion
Use the C bitwise AND operator to test the mask; testing for equality will fail if additional mask flags are added later. The receiver’s delegate and layout managers can use this information to determine the nature of edits in their respective notification methods.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextStorage.heditedRange
Returns the range of the receiver to which pending changes have been made, whether of characters or of attributes.
Return Value
The range of the receiver to which pending changes have been made, whether of characters or of attributes.
Discussion
The receiver’s delegate and layout managers can use this information to determine the nature of edits in their respective notification methods.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextStorage.hensureAttributesAreFixedInRange:
Ensures that attributes are fixed in the given range.
Parameters
- range
The range of characters whose attributes might be examined.
Discussion
An NSTextStorage object using lazy attribute fixing is required to call this method before accessing any attributes within range. This method gives attribute fixing a chance to occur if necessary. NSTextStorage subclasses wishing to support laziness must call this method from all attribute accessors they implement.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.hfixesAttributesLazily
Returns whether the receiver fixes attributes lazily.
Return Value
YES if the text storage fixes attributes lazily, NO otherwise.
Discussion
By default, custom NSTextStorage subclasses are not lazy, but the provided concrete subclass is lazy by default.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.hfont
Returns the receiver’s font.
Return Value
The receiver's font.
Discussion
In OS X v10.5 and later, if the font has not been set, this method and font-related scripting commands assume Helvetica 12.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hforegroundColor
Returns the text storage's foreground color.
Return Value
The text storage's foreground color.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hinvalidateAttributesInRange:
Invalidates attributes in the specified range.
Parameters
- range
The range of characters whose attributes should be invalidated.
Discussion
Called from processEditing to invalidate attributes when the text storage changes. If the receiver is not lazy, this method simply calls fixAttributesInRange:. If lazy attribute fixing is in effect, this method instead records the range needing fixing.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.hlayoutManagers
Returns the receiver’s layout managers.
Return Value
The receiver's layout managers.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.hparagraphs
Returns an array of the text storage's paragraphs.
Return Value
An array of the text storage's paragraphs.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hprocessEditing
Cleans up changes made to the receiver and notifies its delegate and layout managers of changes.
Discussion
This method is automatically invoked in response to an edited:range:changeInLength: message or an endEditing message if edits were made within the scope of a beginEditing block. You should never need to invoke it directly.
This method begins by posting an NSTextStorageWillProcessEditingNotification to the default notification center (which results in the delegate receiving a textStorageWillProcessEditing: message). Then it fixes attributes. After this, it posts an NSTextStorageDidProcessEditingNotification to the default notification center (which results in the delegate receiving a textStorageDidProcessEditing: message). Finally, it sends a textStorage:edited:range:changeInLength:invalidatedRange: message to each of the receiver’s layout managers using the argument values provided.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.hremoveLayoutManager:
Removes a layout manager from the receiver’s set of layout managers.
Parameters
- aLayoutManager
The layout manager to remove.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextStorage.hsetAttributeRuns:
Sets the receiver’s attribute runs.
Parameters
- attributeRuns
The array of attribute runs to set.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hsetCharacters:
Sets the text storage's text.
Parameters
- characters
The characters to set as the text of the text storage.
Special Considerations
Do not use this method if you are not dealing directly with scriptability. Use NSMutableAttributedString’s mutableString method to return a string object that will be tracked by the corresponding attributed string for modifications.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hsetDelegate:
Sets the receiver’s delegate.
Parameters
- anObject
The new delegate.
Availability
- Available in OS X v10.0 and later.
See Also
Declared In
NSTextStorage.hsetFont:
Sets the text storage's font.
Parameters
- font
The new font.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hsetForegroundColor:
Sets the text storage's foreground color.
Parameters
- color
The new foreground color.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hsetParagraphs:
Sets the text storage's paragraphs.
Parameters
- paragraphs
An array of strings to set as the text storage's paragraphs.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hsetWords:
Sets the text storage's words.
Parameters
- words
An array of strings to set as the text storage's words.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hwords
Returns an array of the text storage's words.
Return Value
An array of the text storage's words.
Special Considerations
Unless you are dealing with scriptability, you should not invoke this method directly.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorageScripting.hConstants
Change notifications
These constants are used in edited:range:changeInLength:.
enum {
NSTextStorageEditedAttributes = 1,
NSTextStorageEditedCharacters = 2
};
Constants
NSTextStorageEditedAttributesAttributes were added, removed, or changed.
Available in OS X v10.0 and later.
Declared in
NSTextStorage.h.NSTextStorageEditedCharactersCharacters were added, removed, or replaced.
Available in OS X v10.0 and later.
Declared in
NSTextStorage.h.
Discussion
These values are also OR'ed together in notifications to inform instances of NSLayoutManager was changed—see textStorage:edited:range:changeInLength:invalidatedRange:.
Declared In
NSTextStorage.hNotifications
NSTextStorageDidProcessEditingNotification
processEditing.Observers other than the delegate shouldn’t make further changes to the text storage. The notification object is the text storage object that processed the edits. This notification does not contain a userInfo dictionary.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.hNSTextStorageWillProcessEditingNotification
processEditing.Observers other than the delegate shouldn’t make further changes to the text storage. The notification object is the text storage object that is about to process the edits. This notification does not contain a userInfo dictionary.
Availability
- Available in OS X v10.0 and later.
Declared In
NSTextStorage.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-06-11)