Unmanaged

struct Unmanaged<T>

A type for propagating an unmanaged object reference.

When you use this type, you become partially responsible for keeping the object alive.

Import import Swift

Static Methods

static func fromOpaque(_:)

Unsafely turn an opaque C pointer into an unmanaged class reference.

This operation does not change reference counts.

let str: CFString = Unmanaged.fromOpaque(ptr).takeUnretainedValue()

Declaration

static func fromOpaque(value: COpaquePointer) -> Unmanaged<T>
static func passRetained(_:)

Create an unmanaged reference with an unbalanced retain. The object will leak if nothing eventually balances the retain.

This is useful when passing an object to an API which Swift does not know the ownership rules for, but you know that the API expects you to pass the object at +1.

Declaration

static func passRetained(value: T) -> Unmanaged<T>
static func passUnretained(_:)

Create an unmanaged reference without performing an unbalanced retain.

This is useful when passing a reference to an API which Swift does not know the ownership rules for, but you know that the API expects you to pass the object at +0.

CFArraySetValueAtIndex(.passUnretained(array), i,
                       .passUnretained(object))

Declaration

static func passUnretained(value: T) -> Unmanaged<T>

Instance Methods

func autorelease()

Perform an unbalanced autorelease of the object.

Declaration

func autorelease() -> Unmanaged<T>
func release()

Perform an unbalanced release of the object.

Declaration

func release()
func retain()

Perform an unbalanced retain of the object.

Declaration

func retain() -> Unmanaged<T>
func takeRetainedValue()

Get the value of this unmanaged reference as a managed reference and consume an unbalanced retain of it.

This is useful when a function returns an unmanaged reference and you know that you're responsible for releasing the result.

Declaration

func takeRetainedValue() -> T
func takeUnretainedValue()

Get the value of this unmanaged reference as a managed reference without consuming an unbalanced retain of it.

This is useful when a function returns an unmanaged reference and you know that you're not responsible for releasing the result.

Declaration

func takeUnretainedValue() -> T
func toOpaque()

Unsafely turn an unmanaged class reference into an opaque C pointer.

This operation does not change reference counts.

let str: CFString = Unmanaged.fromOpaque(ptr).takeUnretainedValue()

Declaration

func toOpaque() -> COpaquePointer