3

使用以下消息时,如何修复错误“不允许将 Objective-C 指针隐式转换为 'const void'”:

NSValue *key = [NSValue valueWithPointer:t];

非常感谢可以提供如果简单的新手术语,为什么此代码会引发此异常的人。

如果有帮助,这是完整的方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
    // Is this a double tap?
    if ([t tapCount] > 1) {
        [self clearAll];
        return;
    }

    // Use the touch object (packed in an NSValue) as the key
    NSValue *key = [NSValue valueWithPointer:t]; // here is where the error is

    // Create a line for the value
    CGPoint loc = [t locationInView:self];
    Line *newLine = [[Line alloc] init];
    [newLine setBegin:loc];
    [newLine setEnd:loc];

    // Put pair in dictionary
    [linesInProcess setObject:newLine forKey:key];
}
4

2 回答 2

1

我在 Big Nerd Range Guide 的第二版中进行该练习时遇到了同样的问题,该指南不包括 ARC。这就是问题出现的地方。他们在这里更新了他们的示例/解决方案代码:http: //www.bignerdranch.com/solutions/iOSProgramming3ed.zip

在其中,您可以看到他们已将该行更改为:

NSValue *key = [NSValue valueWithNonretainedObject:t];
于 2012-03-23T18:51:32.280 回答
0

尝试简单地添加 (_bridge void) !

于 2012-07-10T11:13:58.733 回答