A dynamic byte buffer that bridges to Data
; use NSMutable
when you need reference semantics or other Foundation-specific behavior.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
class NSMutableData : NSData
Overview
NSMutable
and its superclass NSData
provide data objects, or object-oriented wrappers for byte buffers. Data objects let simple allocated buffers (that is, data with no embedded pointers) take on the behavior of Foundation objects. They are typically used for data storage and are also useful in Distributed Objects applications, where data contained in data objects can be copied or moved between applications. NSData
creates static data objects, and NSMutable
creates dynamic data objects. You can easily convert one type of data object to the other with the initializer that takes an NSData
object or an NSMutable
object as an argument.
The following NSData
methods change when used on a mutable data object:
When called, the bytes are immediately copied and then the buffer is freed.
NSMutable
is “toll-free bridged” with its Core Foundation counterpart, CFData
. See Toll-Free Bridging for more information on toll-free bridging.
Important
The Swift overlay to the Foundation framework provides the Data
structure, which bridges to the NSMutable
class and its immutable superclass NSData
. For more information about value types, see Working with Cocoa Frameworks in Using Swift with Cocoa and Objective-C (Swift 4.1).