Is there any op operation in objective-c that we can only use to set a breakpoint

The code should not have any effect. It should be executed everywhere. It does not generate a compiler warning.

Basically, sometimes I want to do NSAssert. However, rather than NSAssert, I sometimes want to make my if {} mine. This way I can just set or disable a breakpoint

This is currently what I am doing.

if ( entityName==@ "Business") { error=nil; //Some code for breakpoint. I want something that do nothing actually. } 

It just happens that I have a variable called error that I will no longer use. But what would be a good alternative

I also tried [nil donothing]; but this led to a compiler error.

+7
source share
5 answers

Try the following:

 while (false); 

There are other possibilities, such as if (false) or even a single-semicolon string ; , but in those cases, execution stops at the next command, possibly because the compiler simply excludes these empty code fragments. Using while has the advantage that execution will stop at this line (unless of course you set a breakpoint there).

+7
source

You can specify the conditions of the breakpoint, hold the option and command and click the breakpoint, you should get a pop-up window. In the condition field, yo can enter something like

 [entityName isEqualToString:@"Business"] 

(Note that you must compare strings with -isEqualToString: not == , since the latter compares the pointers, not the characters in the strings themselves.)

Using a condition at a breakpoint, you do not need to execute the if statement at all, nor enable or disable validation without recompiling. You can do a lot with breakpoint settings, for example, whether it automatically logs a message or runs a debugger command, etc.

+3
source

In C, you can have the no-op command, just putting a semicolon only on a line:

 if (TRUE) { ; // Neutral operation } 

In Objective-C, you can do the same, your program stops before the next line, as you can see here:

enter image description here

+3
source

You do not compare 2 lines directly; try [NSString isEqualToString:]

+2
source

you can use __asm int 3;

 if ([entityName isEqualToString:@"Business"]) { __asm int 3; } 

From CFInternal.h .

 #if defined(__ppc__) || defined(__ppc64__) #define HALT asm __volatile__("trap") #elif defined(__i386__) || defined(__x86_64__) #if defined(__GNUC__) #define HALT asm __volatile__("int3") #elif defined(_MSC_VER) #define HALT __asm int 3; #else #error Compiler not supported #endif #endif if ([entityName isEqualToString:@"Business"]) { HALT; } 
0
source

All Articles