Unmanaged
An
Unmanaged<T>
instance wraps a CoreFoundation typeT
, preserving a reference to the underlying object as long as theUnmanaged
instance itself is in scope. There are two ways to get a Swift-managed value out of anUnmanaged
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.