Xcode에서 경고를 억제하는 방법이 있습니까?
Xcode에서 경고를 억제하는 방법이 있습니까?
예를 들어 문서화되지 않은 메소드를 호출하고 있으며 메소드가 헤더에 없으므로 컴파일에 대한 경고가 표시됩니다. 경고를 중지하기 위해 헤더에 추가 할 수 있다는 것을 알고 있지만 경고를 억제하기 위해 헤더에 헤더를 추가하는 것 이외의 방법이 있는지 궁금합니다 (따라서 헤더를 깨끗하고 표준으로 유지할 수 있음)? pragma 또는 무엇인가?
Xcode 3 및 llvm-gcc-4.2를 사용하여 파일별로 경고를 비활성화하려면 다음을 사용할 수 있습니다.
#pragma GCC diagnostic ignored "-Wwarning-flag"
여기서 경고 이름은 gcc 경고 플래그입니다.
이것은 명령 행의 모든 경고 플래그를 대체합니다. 그러나 모든 경고와 함께 작동하지는 않습니다. CFLAGS에 -fdiagnostics-show-option을 추가하면 해당 경고를 비활성화하는 데 사용할 수있는 플래그를 확인할 수 있습니다.
사용하지 않는 변수 경고 를 억제하는 간단한 방법이 있습니다 .
#pragma unused(varname)
편집 : 출처 : http://www.cocoadev.com/index.pl?XCodePragmas
업데이트 : 새로운 솔루션, 더 강력한 솔루션을 얻었습니다.
- 프로젝트> 활성 대상 편집> 빌드 탭을여십시오.
- 아래
User-Defined
: 찾기 (또는 찾지 못한 경우 작성) 키 :로GCC_WARN_UNUSED_VARIABLE
설정하십시오NO
.
편집 -2 예 :
BOOL ok = YES;
NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self);
컴파일러는에 대해 사용되지 않은 변수 경고를 표시합니다 ok
.
해결책:
BOOL ok = YES;
#pragma unused(ok)
NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self);
추신 : 당신은 또한 다른 경고를 설정 / 재설정 할 수 있습니다 : GCC_WARN_ABOUT_RETURN_TYPE
:YES/NO
gcc의 경우 사용할 수 있습니다
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow-ivar"
// your code
#pragma GCC diagnostic pop
여기에서 GCC pragma에 대해 배우고 경고의 경고 코드를 얻으려면 Report Navigator (Command + 9)로 이동하여 최상위 빌드를 선택하고 로그 (오른쪽의 '='단추)를 펼친 후 하단과 경고 코드는 다음과 같이 대괄호 안에 있습니다[-Wshadow-ivar]
clang의 경우 사용할 수 있습니다
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow-ivar"
// your code
#pragma clang diagnostic pop
개별 파일에 대한 경고를 표시하지 않으려면 다음을 수행하십시오.
xcode 프로젝트에서 파일을 선택하십시오. get get info를 누르면 빌드 옵션이있는 페이지로 이동하여 경고를 무시하려면 -Wno-를 입력하십시오.
-아니
예 :
미사용 파라미터
프로젝트 설정에서 빌드 탭 페이지의 하단에있는 GCC 경고를 보면 경고 이름을 얻을 수 있습니다. 각 경고를 클릭하면 경고 매개 변수 이름이 표시됩니다.
예 :
함수 매개 변수가 선언과 별도로 사용되지 않을 때마다 경고합니다. [GCC_WARN_UNUSED_PARAMETER,-사용하지 않는 매개 변수]
경고를 제거하려면 : 해당 오브젝트에 대한 카테고리 인터페이스를 작성하십시오.
@interface NSTheClass (MyUndocumentedMethodsForNSTheClass)
-(id)theUndocumentedMethod;
@end
...
@implementation myClass : mySuperclass
-(void) myMethod {
...
[theObject theUndocumentedMethod];
...
}
따로, 운송 코드에서 문서화되지 않은 메소드를 호출하지 않도록 강력히 권장합니다. 인터페이스는 변경 될 수 있으며 변경 될 것이며 이는 귀하의 잘못입니다.
With Objective-C, a number of serious errors only appear as warnings. Not only do I never disable warnings, I normally turn on "Treat warnings as errors" (-Werror).
Every type of warning in your code can be avoided by doing things correctly (normally by casting objects to the correct type) or by declaring prototypes when you need them.
http://nshipster.com/pragma/#inhibiting-warnings - skip to inhibiting warnings section
Create a new, separate header file called 'Undocumented.h' and add it to your project. Then create one interface block for each class you want to call undocumented functions on and give each a category of '(Undocumented)'. Then just include that one header file in your PCH. This way your original header files remain clean, there's only one other file to maintain, and you can comment out one line in your PCH to re-enable all the warnings again.
I also use this method for depreciated functions in 'Depreciated.h' with a category of '(Depreciated)'.
the best part is you can selectively enable/disable individual warnings by commenting or uncommenting the individual prototypes.
Suppressing that particular warning is not safe. The compiler needs to know the types of the arguments and returns to a method to generate correct code.
For example, if you're calling a method like this
[foo doSomethingWithFloat:1.0];
that takes a float, and there is no prototype visible, then the compiler will guess that the method takes a double, not a float. This can cause crashes and incorrectly interpreted values. In the example above, on a little endian machine like the intel machines, the receiver method would see 0 passed, not 1.
You can read why in the i386 ABI docs, or you can just fix your warnings. :-)
참고URL : https://stackoverflow.com/questions/194666/is-there-a-way-to-suppress-warnings-in-xcode
'IT story' 카테고리의 다른 글
쉘 스크립트로 파싱하기에 적합한 리눅스 박스의 총 실제 메모리 (RAM)를 어떻게 알 수 있습니까? (0) | 2020.07.25 |
---|---|
UInt32에 비해 값이 너무 크거나 작습니다. TFS 체크인 오류 (0) | 2020.07.25 |
Visual Studio에서 "코드 4로 종료 된 xcopy"가 표시 될 때 잘못된 문제 (0) | 2020.07.25 |
Httpclient 요청에 대한 사용자 정의 헤더 (0) | 2020.07.25 |
메소드 목록을 표시하는 Visual Studio 창 (0) | 2020.07.25 |