1

The following code which compiled so far in standard Xcode versions now fails in Xcode 26 beta 2. Has anything changed in the new Swift compiler or was this an issue in my code:

func makeAudioTapProcessor() -> MTAudioProcessingTap? {
    var callbacks = MTAudioProcessingTapCallbacks(
        version: kMTAudioProcessingTapCallbacksVersion_0,
        clientInfo: UnsafeMutableRawPointer(Unmanaged.passRetained(self).toOpaque()),
        init: tapInit,
        finalize: tapFinalize,
        prepare: tapPrepare,
        unprepare: tapUnprepare,
        process: tapProcess)
    
     
    var tap: Unmanaged<MTAudioProcessingTap>?
    let status = 
 MTAudioProcessingTapCreate(kCFAllocatorDefault, &callbacks, kMTAudioProcessingTapCreationFlag_PreEffects, 
   &tap)

    if status != noErr {
        print("Failed to create audio processing tap")
    }
    return tap?.takeRetainedValue()
}

Error is in MTAudioProcessingTapCreate function where the function rejects argument of type Unmanaged<MTAudioProcessingTap>? for &tap

Cannot convert value of type 'UnsafeMutablePointer<Unmanaged?>' to expected argument type 'UnsafeMutablePointer<MTAudioProcessingTap?>'

5
  • 1
    The function signature simply changed in the new SDK version. This is trivial to fix, no? Just get rid of the Unmanaged. Commented Jun 25 at 16:39
  • @Sweeper Yes, I did that but I am wondering if that is correct thing to do (who owns the memory now vis-a-vis before). Commented Jun 25 at 16:42
  • 2
    That should be correct. Comparing the difference in the header files, the Xcode 26 version has an extra CM_RETURNS_RETAINED_PARAMETER macro. Swift probably recognises this and understands that it is a retained value, so there is no need for Unmanaged. Commented Jun 25 at 16:44
  • Where do you see CM_RETURNS_RETAINED_PARAMETER? I still see this in the documentation in XCode@available(iOS 6.0, *) public func MTAudioProcessingTapCreate(_ allocator: CFAllocator?, _ callbacks: UnsafePointer<MTAudioProcessingTapCallbacks>, _ flags: MTAudioProcessingTapCreationFlags, _ tapOut: UnsafeMutablePointer<MTAudioProcessingTap?>) -> OSStatus Commented Jun 25 at 16:50
  • 2
    Open a .m file, import Media Toolbox, then type MTAudioProcessingTapCreate, then command click on it to go to the header. Commented Jun 25 at 16:53

1 Answer 1

1

The headers have changed between Xcode versions. The last parameter of MTAudioProcessingTapCreate is now marked CM_RETURNS_RETAINED_PARAMETER, which is an alias for CF_RETURNS_RETAINED.

 MT_EXPORT OSStatus MTAudioProcessingTapCreate(
         CFAllocatorRef CM_NULLABLE allocator,
         const MTAudioProcessingTapCallbacks * CM_NONNULL callbacks,
         MTAudioProcessingTapCreationFlags flags,
         CM_RETURNS_RETAINED_PARAMETER MTAudioProcessingTapRef CM_NULLABLE * CM_NONNULL tapOut)

This indicates that the function expects the caller to own the MTAudioProcessingTap instance (as functions with Create in their names often do). Therefore, when this is imported into Swift, it can be imported as a managed reference because Swift understands its ownership semantics.

The fix is trivial - just remove the Unmanaged wrapper.

var tap: MTAudioProcessingTap?
Sign up to request clarification or add additional context in comments.

Comments

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.