I have a such code:
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(updateFrame)]];
[invocation setTarget:self];
[invocation setSelector:@selector(updateFrame)];
displayLink_ = [[CADisplayLink displayLinkWithTarget:invocation selector:@selector(invoke)] retain];
[displayLink_ setFrameInterval:1];
[displayLink_ addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
At iOS 6.0 (in 5.1 this code works ok) when this code calling I have two variants: EXC_BAD_ACCESS or 'call to unrecognized selector "invoke"'. It is seem that displayLinkWithTarget:selector: method doesn't retain target. When i add [invocation retain] line, code become to work ok. Is it bug of iOS 6.0?
This is useful related information, not an answer.
Rather than use
NSInvokation
you can use a weak proxy as I have done in my actual answer to this question. It's very simple, here's the code:JAWeakProxy.h:
JAWeakProxy.m:
NOTE: This is ARC code, you'll need to
autorelease
inweakProxyWithTarget:
if not using ARC.I had the same problem. I actually want a weak reference but since it's documented as strong and behaves that way in other versions of iOS I use a weak proxy object to forward the selector to where I really want it to go. To ensure the proxy object is retained I had to figure out a way to safely retain it on broken versions of iOS without over-retaining it for non-broken versions. I came up with a very elegant one-line solution (the line after the four lines of comments explaining it):
Remember to
#import <objc/runtime.h>
. Using an associated object is great because it gets released when the display link isdealloc
ed and on non-broken versions of the OS it simply means the object is retained twice by the display link.