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?>'
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?