Swift의 #ifdef DEBUG 방식
2225 단어 Swift
#ifdef DEBUG
// ...
#endif
하지만 스wift에서는 같은 기술을 할 수 없다.Apple 문서에 따라 다음과 같이 바꿀 수 있습니다.
#if build_configuration
// ...
#elseif build_configuration
// ...
#else
// ...
#endif
써 보았다#if DEBUG ...
,하지만 기대했던 동작은 하지 않았다.다음과 같이 Apple 문서를 자세히 읽으십시오.
Swift code and Objective-C code are conditionally compiled in different ways. Swift code can be conditionally compiled based on the evaluation of build configurations. Build configurations include the literal true and false values, command line flags, and the platform-testing functions listed in the table below. You can specify command line flags using -D <#flag#>.
컴파일할 때의 옵션인 것 같습니다.
-D flag
X코드의 Build Settings를 보세요. Swift Compuiler-Custom Flags에는 Other Swift Flags라는 프로젝트가 있습니다.여기에
-D DEBUG
의 정의를 추가하여 방금 코드가 순조롭게 운행되었다.(Xcode6은 여전히 일반적이어서 캡처를 붙일 수 없어서 유감입니다.)
[추기 2014.09.2] Xcode6가 정식으로 출시되었고 캡처가 붙여졌습니다.
새 프로젝트를 만든 후 Processor Macros는 이전과 같이 정의했지만, Other Swift Flags는 비어 있습니다.
Xcode6가 발매되었을 때 처음부터 정의가 됐으면 좋겠다
DEBUG=1
.[추기 2014.09.21] 엑스코드6가 공식 발표를 해서 확인했지만 아쉽게도 베타는 GM 때와 마찬가지로 비어 있었다.서운하다
참고 자료
Reference
이 문제에 관하여(Swift의 #ifdef DEBUG 방식), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/qmihara/items/a6b88b74fe64e1e05ca4텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)