开发者

How to address a "Implicit conversion of an Objective-C pointer to 'const void' is disallowed" error when using [NSValue valueWithPointer:t]?

开发者 https://www.devze.com 2023-03-30 21:33 出处:网络
How do I fix the error \"Implicit conversion of an Objective-C pointer to \'const void\' is disallowed\" when using the following message:

How do I fix the error "Implicit conversion of an Objective-C pointer to 'const void' is disallowed" when using the following message:

NSValue *key = [NSValue valueWithPointer:t];

Extra thanks goes to the one can offer why this code throws this exception if simple, newbie terms.

Here is the full method if it helps:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouc开发者_StackOverflow中文版h *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];
}


I ran into the same problem working on that exercise in the second edition of the Big Nerd Range Guide, which doesn't cover ARC. That's where the issue arises. They've updated their example/solution code here: http://www.bignerdranch.com/solutions/iOSProgramming3ed.zip

Within that, you can see they've changed that line to:

NSValue *key = [NSValue valueWithNonretainedObject:t];


Try to simply add (_bridge void) !

0

精彩评论

暂无评论...
验证码 换一张
取 消