将'CFTypeRef _Nullable'(又名'const void *')传递给'void * _Nullable'类型的参数会丢弃限定符

时间:2017-03-18 03:35:10

标签: ios objective-c xcode automatic-ref-counting

我正在尝试使用旧的项目在iOS 10.2中使用ARC(该项目在iOS 4下开始)。我在两个地方收到以下警告

    Passing 'CFTypeRef _Nullable' (aka 'const void *') to parameter of type 'void * _Nullable' discards qualifiers

第一次发生在第setUpPlayQueue行的CFBridgingRetain(self),

- (void)setUpPlayQueue
{
    AudioQueueNewOutput(
        &audioFormat,
        playCallback,
        CFBridgingRetain(self), 
        NULL,                   // run loop
        kCFRunLoopCommonModes,  // run loop mode
        0,                      // flags
        &playQueue
        );

    self.gain = 1.0;
}
setUpPlayQueue

调用

setUpAudio

- (void)setUpAudio
{
    if (playQueue == NULL)
    {
        [self setUpAudioSession];
        [self setUpPlayQueue];
        [self setUpPlayQueueBuffers];
    }
}

第二次发生在primePlayQueueBuffersplayCallback(CFBridgingRetain(self), playQueue, playQueueBuffers[t]);

- (void)primePlayQueueBuffers
{
    for (int t = 0; t < NUMBER_AUDIO_DATA_BUFFERS; ++t)
    {
        playCallback(CFBridgingRetain(self), playQueue, playQueueBuffers[t]);
    }
}
primePlayQueueBuffers

调用

start

- (void)start
{
    if (!playing)
    {
        playing = YES;
        [self primePlayQueueBuffers];
        AudioQueueStart(playQueue, NULL);
    }
}

通过为构建目标设置-fno-objc-arc编译器标志(如here所述),我设法为AudioBufferPlayer(保存这些方法的文件)禁用ARC,并将项目设置为建立。描述的类似问题here herehere无法真正解决此问题。

有人可以帮忙吗?感谢

更新

根据Martin(和Amin)的建议,当我使用(__bridge void *)(self)代替CFBridgingRetain(self) - 清除-fno-objc-arc编译器标志时 - 两个警告都会消失。但是当我构建Xcode然后报告

    Existing instance variable 'delegate' for property 'delegate' with assign attribute must be __unsafe_unretained

这是委托界面

@interface AudioBufferPlayer : NSObject <AVAudioSessionDelegate>

{
    id<AudioBufferPlayerDelegate> delegate;
    BOOL playing;
    Float32 gain;
    AudioStreamBasicDescription audioFormat;

    /// the audio queue object being used for playback
    AudioQueueRef playQueue;

    /// the audio queue buffers for the playback audio queue
    AudioQueueBufferRef playQueueBuffers[NUMBER_AUDIO_DATA_BUFFERS];

    /// the number of audio data packets to use in each audio queue buffer
    UInt32 packetsPerBuffer;

    /// the number of bytes to use in each audio queue buffer
    UInt32 bytesPerBuffer;
}

/*! 
 * The delegate that fills up the audio buffers. This is a weak reference; the 
 * delegate is not retained. 
 */
@property (nonatomic, assign) id<AudioBufferPlayerDelegate> delegate;

Transitioning to ARC Release Notes中说

  

iOS 4中不支持弱引用。

当我将属性引用更改为strong并尝试构建时,Xcode最初报告了一些错误,包括一个由dealloc引起的错误,我有理由确定Xcode已在代码中恢复(我知道我以前已删除它)。但是在关闭Xcode并重新打开它之后,我现在能够成功构建和运行项目,没有任何错误或警告。

感谢Martin和Amin。非常感谢。

0 个答案:

没有答案