Tuesday, April 28, 2015

Unmanaged

Nate Cook:

An Unmanaged<T> instance wraps a CoreFoundation type T, preserving a reference to the underlying object as long as the Unmanaged instance itself is in scope. There are two ways to get a Swift-managed value out of an Unmanaged instance:

  • takeRetainedValue(): returns a Swift-managed reference to the wrapped instance, decrementing the reference count while doing so—use with the return value of a Create Rule function.

  • takeUnretainedValue(): returns a Swift-managed reference to the wrapped instance without decrementing the reference count—use with the return value of a Get Rule function.

In practice, you’re better off not even working with Unmanaged instances directly. Instead, take... the underlying instance immediately from the function’s return value and bind that.

Comments RSS · Twitter

Leave a Comment