I'm not using ARC
so I can't use weak.
Please let me know, that what can I do to not allow the NSTimer to retain the target which in my case is self.
Asked
Active
Viewed 151 times
0
-
2Why don't you want the timer to retain its target? Show your relevant code and explain what you are trying to do. – rmaddy Apr 22 '14 at 23:13
-
related: http://stackoverflow.com/questions/10754827/how-to-zeroing-weak-references-under-non-arc – Bryan Chen Apr 22 '14 at 23:19
-
2unsafe_unretained. But why are you not using arc and why do you want to do what you describe in your question? – Gruntcakes Apr 22 '14 at 23:22
1 Answers
0
You might just go ahead and create a version of NSTimer that does not retain its target
+ (NSTimer *) scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo
{
NSWeakTimerTarget* timerTarget = [[NSWeakTimerTarget alloc] init];
timerTarget.target = aTarget;
timerTarget.selector = aSelector;
timerTarget.timer = [NSTimer scheduledTimerWithTimeInterval:ti target:timerTarget selector:@selector(fire) userInfo:userInfo repeats:yesOrNo];
return timerTarget.timer;
}

shalzangel
- 387
- 2
- 10
-
There are several things not to like with that gist. The most obvious one is evading one of Apple’s class prefixes—especially not NS. Honestly: **DO NOT DO THAT!** Ever. The rest is too long to fit this narrow comment box. I’ll post an answer later on. – danyowdee Apr 23 '14 at 09:07
-