Generic Structure

AutoreleasingUnsafeMutablePointer

A mutable pointer addressing an Objective-C reference that doesn’t own its target.

Declaration

@frozen struct AutoreleasingUnsafeMutablePointer<Pointee>

Overview

Pointee must be a class type or Optional<C> where C is a class.

This type has implicit conversions to allow passing any of the following to a C or ObjC API:

  • nil, which gets passed as a null pointer,

  • an inout argument of the referenced type, which gets passed as a pointer to a writeback temporary with autoreleasing ownership semantics,

  • an UnsafeMutablePointer<Pointee>, which is passed as-is.

Passing pointers to mutable arrays of ObjC class pointers is not directly supported. Unlike UnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee> must reference storage that does not own a reference count to the referenced value. UnsafeMutablePointer’s operations, by contrast, assume that the referenced storage owns values loaded from or stored to it.

This type does not carry an owner pointer unlike the other C*Pointer types because it only needs to reference the results of inout conversions, which already have writeback-scoped lifetime.

Topics

Converting Pointers

init?<U>(UnsafeMutablePointer<U>?)

Explicit construction from an UnsafeMutablePointer.

init<U>(UnsafeMutablePointer<U>)

Explicit construction from an UnsafeMutablePointer.

Accessing a Pointer's Memory

var pointee: Pointee

Retrieve or set the Pointee instance referenced by self.

subscript(Int) -> Pointee

Access the ith element of the raw array pointed to by self.

Comparing Pointers

Type Aliases

typealias AutoreleasingUnsafeMutablePointer.Stride

A type that represents the distance between two values.

Initializers

init(Builtin.RawPointer)

Creates a pointer from a raw value.

init?(AutoreleasingUnsafeMutablePointer<Pointee>?)

Creates a new pointer from the given pointer.

init?(OpaquePointer?)

Creates a new typed pointer from the given opaque pointer.

init(OpaquePointer)

Creates a new typed pointer from the given opaque pointer.

init(AutoreleasingUnsafeMutablePointer<Pointee>)

Creates a new pointer from the given pointer.

init?(bitPattern: Int)

Creates a new pointer from the given address, specified as a bit pattern.

init?(bitPattern: UInt)

Creates a new pointer from the given address, specified as a bit pattern.

Instance Properties

var customMirror: Mirror

The custom mirror for this instance.

var debugDescription: String

A textual representation of the pointer, suitable for debugging.

var hashValue: Int

The hash value.

Instance Methods

func advanced(by: Int) -> AutoreleasingUnsafeMutablePointer<Pointee>

Returns a pointer offset from this pointer by the specified number of instances.

func distance(to: AutoreleasingUnsafeMutablePointer<Pointee>) -> Int

Returns the distance from this pointer to the given pointer, counted as instances of the pointer’s Pointee type.

func hash(into: inout Hasher)

Hashes the essential components of this value by feeding them into the given hasher.

func predecessor() -> AutoreleasingUnsafeMutablePointer<Pointee>

Returns a pointer to the previous consecutive instance.

func successor() -> AutoreleasingUnsafeMutablePointer<Pointee>

Returns a pointer to the next consecutive instance.

Operator Functions

static func < (AutoreleasingUnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool

Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.

static func < (AutoreleasingUnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool

Returns a Boolean value indicating whether the first pointer references an earlier memory location than the second pointer.

static func <= (AutoreleasingUnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool

Returns a Boolean value indicating whether the value of the first argument is less than or equal to that of the second argument.

static func > (AutoreleasingUnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool

Returns a Boolean value indicating whether the value of the first argument is greater than that of the second argument.

static func >= (AutoreleasingUnsafeMutablePointer<Pointee>, AutoreleasingUnsafeMutablePointer<Pointee>) -> Bool

Returns a Boolean value indicating whether the value of the first argument is greater than or equal to that of the second argument.

Relationships

Conforms To

See Also

C and Objective-C Pointers

struct OpaquePointer

A wrapper around an opaque C pointer.