使用以下消息时,如何修复错误“不允许将 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];
}