ARC and NSValue wrapping


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

This is throwing a compiler error telling me that implicit coercion of an Objective-C point to (const void *) is not allowed. There is a thread on Stack Overflow about this part, and it offers a suggestion of explicitly casting to (const void *) but they also say this is bad coding.

Should I just explicitly cast or is there a better way of coding this part?

[edit] Okay, so explicitly casting using (__bridge const void *) works, but I’m still worried that people seem to think this is not something that should be done. If there is a more compliant way to do this, or if there is a reason this is compliant I would appreciate hearing about it.


With ARC, you’ll want to use [NSValue valueWithNonretainedObject:touch] instead of valueWithPointer:.


Thanks, Joe. I had seen that posted elsewhere on the intertubes, but coming from you I trust it :wink:


Thanks! I’d been reading up on bridged casts and trying all kinds of things. I should always come here first.