Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Hey guys,
I am stuck and I am just wondering how to create breakpoint. For example,
I have an if statement and if a certain thing happens I want the method to break so that the rest of the code in that method will not run. Can anyone help please?

Code:
Code:
if ([inputName.text isEqualToString:@""]) {
      //break code;
}
 
Well if you mean a breakpoint as in the code stops so you can debug it then it depends on your IDE, in X-Code you have to click on the far left of the editing window (the "gutter") at the point where you want the code to stop. You can check out the X-Code debugging guide for more information:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeDebugging/index.html

If by breakpoint you mean that the function ends then you can just return a value (depending on what the function is meant to return) or if you want to simply end the if statement then "break;" will do the trick.
 
Ya, I just mean that I want the function to end, I don't think breakpoint was the proper word for that. What I am trying to do is more like the "break;" command.

However, I get an error when I put "break;" into an if statement telling me that its looking for a loop statement not an if.

Any ideas?
 
Alright I get what your saying but what if the if statement is in an IBAction function such as a button? Can you still return a value? And if so what do u return?
 
Alright I get what your saying but what if the if statement is in an IBAction function such as a button? Can you still return a value? And if so what do u return?
IBAction doesn't return a value. IBAction is just a special keyword that actually means the same thing as void. And voids don't return values. If you want to stop execution of some other type of method, though, just be sure to return a value of the type that is defined as the return type for that method.

Hmm, unless you are wanting your IBAction to return a value. Is that the case? If so, please explain why you need to do this.
 
Ohh right right. I see what you are saying. I got it working. Thank you very much for your help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.