iOS Developer Library

Developer

UIKit Framework Reference NSMutableAttributedString UIKit Additions Reference

Options
Deployment Target:

On This Page
Language:

NSMutableAttributedString

Inheritance


Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 3.2 and later.

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.

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

    Declaration

    Swift

    func fixAttributesInRange(_ range: NSRange)

    Objective-C

    - (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 YEStrue from the fixesAttributesLazily method should avoid directly calling fixAttributesInRange: or else bracket such calls with beginEditing and endEditing messages.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func readFromData(_ data: NSData, options opts: [NSObject : AnyObject]?, documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>, error error: NSErrorPointer) -> Bool

    Objective-C

    - (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

    YEStrue if the attributed string is created successfully; otherwise NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.

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

    Declaration

    Swift

    func readFromFileURL(_ url: NSURL!, options opts: [NSObject : AnyObject]!, documentAttributes dict: AutoreleasingUnsafeMutablePointer<NSDictionary?>, error error: NSErrorPointer) -> Bool

    Objective-C

    - (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

    YEStrue if the attributed string is created successfully; otherwise NOfalse.

    Discussion

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

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 7.0 and later.