6

In Swift I am trying to create an AUSamplerBankPresetData object which requires an Unmanaged<CFURL> object.

How do I convert a URL object into Unmanaged<CFURL> in swift?

1 Answer 1

7

You first need to convert your URL into a CFURL. This can be done with an unconditional cast so:

let cfurl = url as CFURL

Then, to create an unmanaged reference to that CFURL you'll need to use one of the functions outlined here to create an Unmanaged object. Make sure you choose the right one for your application. The example below will increment the reference count, so you will need to make sure that it is decremented later.

var um = Unmanaged<CFURL>.passRetained(cfurl)
Sign up to request clarification or add additional context in comments.

1 Comment

Note that passRetained() increases the refcount, so this must be balanced eventually to avoid a memory leak.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.