Xcode switch / case termination and warnings

How can I execute Xcode (4.5, 4G182) in case of building a switch / case and notify me of missing cases?

For instance:

for (int i=0;i<[flat elementCount];i++) { NSPoint elements[3]; NSBezierPathElement elem=[flat elementAtIndex:i associatedPoints:elements]; switch (elem ) { case NSMoveToBezierPathElement: break; case NSLineToBezierPathElement: break; case 

I have seen this in the past. He also warned me of missing cases when the unit was closed. How can you achieve this - Xcode 4.5?

Edit: Verify that the Switch counters are turned on and I have no warnings.

Here is a small example where the job ends:

 typedef enum { kThisCase = 0, kThatValue = 1, kLastOne = 2 } myEnum; myEnum var= kLastOne; switch (var) { case kThatValue: break; case kLastOne: break; case 

CTRL + SPACE here gives me the remaining possible value of myEnum

completion is workingcompletion is not working

In the case of the completion of the NSBezierPathElement, when I add this:

 typedef enum { NSMoveToBezierPathElement, NSLineToBezierPathElement, NSCurveToBezierPathElement, NSClosePathBezierPathElement } NSBezierPathElement; 

(copied from the quick access toolbar) before building the switch, autocomplete works, but there are no warnings.

Content of NSBezierPath.h

 enum { NSMoveToBezierPathElement, NSLineToBezierPathElement, NSCurveToBezierPathElement, NSClosePathBezierPathElement }; typedef NSUInteger NSBezierPathElement; 

Is this an explanation for shutting down? Shouldn't this enumeration be of type NSBezierPathElement?

This does not match the quick access toolbar. In the quick access panel, I have the following: typedef enum { NSMoveToBezierPathElement, NSLineToBezierPathElement, NSCurveToBezierPathElement, NSClosePathBezierPathElement} NSBezierPathElement;

+4
source share
1 answer

You need a compiler setting, which is enabled by default. Find “case” in the build settings and one (title) named “Check Switch Statement”, this is GCC_WARN_CHECK_SWITCH_STATEMENTS.

I think it is necessary that the enumeration be correctly defined, and not like NSInteger, etc. If the constants are integers, not an enumeration, then checking will not help, because the compiler does not have integers of knowledge.

In addition, it is very important to remove the default sentence :. If it is there, then you implicitly handle all the missing cases in this, so the warning does not start!

+3
source

Source: https://habr.com/ru/post/1436100/


All Articles