This is on XCode 6.2.
If I run the app in release mode it will crash, but with optimizations off it does not crash. The code looks straightforward. I have programmed Obj
I had a similar scenario. Since I believe most people coming to this question are looking more for insight on what potentially causes this, I'll share what happened with my code.
I am using ReactiveCocoa in my project, and I set up a reactive signal to be fired anytime I had a UIView
's selected stated change. It was custom view that mimics a button, but is actually derived from UIView
. In this block, I was then setting all of the other button-like views in my view to have their selected states set to NO
.
Without optimizations, this was executing fine. With optimizations, it descended into an infinite loop. Weird, eh?
In short, in my scenario, I changed this code:
[allButtons makeObjectsPerformSelector:@selector(setSelected:) withObject:@(NO)];
to this
for(MyButtonLikeView* button in allButtons) {
if(button.selected) {
button.selected = NO;
}
}
I know this isn't likely going to be a solution to your problem. But I hope it's useful.
In summary, use your debugger and be on the lookout for code that is correct in Debug, but may suddenly stop working in Release.