NSMutableAttributedString UIKit Additions Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 3.2 and later.
Declared in
NSAttributedString.h
Related sample code

Overview

The UIKit framework adds methods to NSMutableAttributedString to support replacing the string with contents of an external document and fixing attribute inconsistencies within a character range.

Tasks

New Methods

Instance Methods

fixAttributesInRange:

Cleans up font, paragraph style, and attachment attributes within the given range.

- (void)fixAttributesInRange:(NSRange)range
Parameters
range

The character range within which to fix attributes. Raises an NSRangeException if any part of range lies beyond the end of the receiver’s characters.

Discussion

Removes attachment attributes assigned to characters other than NSAttachmentCharacter, assigns default fonts to characters with illegal fonts for their scripts and otherwise corrects font attribute assignments, and assigs the first paragraph style attribute value in each paragraph to all characters of the paragraph.

This method extends the range as needed to cover the last paragraph partially contained.

Raises an NSRangeException if any part of aRange lies beyond the end of the receiver’s characters.

NSTextStorage subclasses that return YES from the fixesAttributesLazily method should avoid directly calling fixAttributesInRange: or else bracket such calls with beginEditing and endEditing messages.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSAttributedString.h

readFromData:options:documentAttributes:error:

Sets the contents of the receiver from the stream of the given data object.

- (BOOL)readFromData:(NSData *)data options:(NSDictionary *)opts documentAttributes:(NSDictionary **)dict error:(NSError **)error
Parameters
data

The data object providing text data.

opts

Keys specifying the types of documents and other document import options. See Option_keys_for_importing_documents for a list of keys.

dict

On return, the dictionary (if provided) contains keys representing various document-wide attributes. See Keys_for_Options_and_Document_Attributes_Dictionaries for a list of keys.

error

Upon return, if an error occurs, contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.

Return Value

YES if the attributed string is created successfully; otherwise NO.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSAttributedString.h

readFromFileURL:options:documentAttributes:error:

Sets the contents of the receiver from the file at the given URL.

- (BOOL)readFromFileURL:(NSURL *)url options:(NSDictionary *)opts documentAttributes:(NSDictionary **)dict error:(NSError **)error
Parameters
url

The location of the file providing text data.

opts

Keys specifying the types of documents and other document import options. See Option_keys_for_importing_documents for a list of keys.

dict

On return, the dictionary (if provided) contains keys representing various document-wide attributes. See Keys_for_Options_and_Document_Attributes_Dictionaries for a list of keys.

error

Upon return, if an error occurs, contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.

Return Value

YES if the attributed string is created successfully; otherwise NO.

Discussion

For RTF formatted files, the contents of the file are appended to the previous string instead of replacing the previous string.

Availability
  • Available in iOS 7.0 and later.
Declared In
NSAttributedString.h