UTTypeCreatePreferredIdentifierForTag returns Unmanaged<CFStringRef> , so you need to get the value from the Unmanaged object before you can use it:
var unmanagedFileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, nil) var fileUTI = unmanagedFileUTI.takeRetainedValue()
Please note that I call takeRetainedValue() , since UTTypeCreatePreferredIdentifierForTag returns the object for which we are responsible for the release. Comments on takeRetainedValue() say:
Get the value of this unmanaged link as a managed link and consume its unbalanced persistence.
This is useful when a function returns an unmanaged link and you know that you are responsible for freeing the result.
If you are returning an Unmanaged object back from a function where you are sure you are not responsible for freeing this object, call takeUnretainedValue() .
source share