好的,这是我的第一篇文章,在Objective-C上还是很新,但是在这里:
我当前正在创建一个项目,该项目将创建第二个队列以生成一堆NSTimers并将其关闭。由于我不想停止主要队列,因此我认为大中央车站是最佳路线。
目前,我有一个执行以下操作的UIButton:
- (IBAction)runTest:(id)sender {
if (!timerQueue) {
timerQueue = dispatch_queue_create("com.myApp.timerQueue", DISPATCH_QUEUE_SERIAL);
}
dispatch_async(timerQueue, ^{[self initiateTest];});
然后...
- (void) initiateTest {
// code to generate timers and execute
}
与所有发生这种情况的viewController关联的头文件如下所示:
@interface ViewController : UIViewController <SomeOtherMgrDelegate> {
dispatch_block_t timerQueue;
}
...
- (IBAction)runTest:(id)sender;
- (void) initiateTest;
问题似乎与生产线有关
timerQueue = dispatch_queue_create("com.myApp.timerQueue", DISPATCH_QUEUE_SERIAL);
这就产生了一个相当冗长的语义问题,内容为:
从不兼容类型'dispatch_queue_t'(又称为'NSObject *')分配给'__strong dispatch_block_t'(aka'void(^ __ strong)(void)')
知道为什么会产生此错误吗?在文档中似乎这是正确的解决方法。
谢谢;让我知道代码中是否还有其他有用的信息!
编辑:所以这是一个相当愚蠢的错误,但对于其他人:确保类型匹配(块/ =队列!)。与viewController关联的.h文件应如下所示:
@interface ViewController : UIViewController <SomeOtherMgrDelegate> {
dispatch_queue_t timerQueue; // This is where the problem was.
}
...
- (IBAction)runTest:(id)sender;
- (void) initiateTest;
最佳答案
您已将timerQueue
声明为dispatch_block_t
的实例,当它应为dispatch_queue_t
时,它是dispatch_queue_create()
的返回类型
关于ios - GCD队列不兼容类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21320708/