#ifdef replacement in the Swift language

前端 未结 17 1884
名媛妹妹
名媛妹妹 2020-11-22 10:35

In C/C++/Objective C you can define a macro using compiler preprocessors. Moreover, you can include/exclude some parts of code using compiler preprocessors.

         


        
17条回答
  •  日久生厌
    2020-11-22 11:27

    In Swift projects created with Xcode Version 9.4.1, Swift 4.1

    #if DEBUG
    #endif
    

    works by default because in the Preprocessor Macros DEBUG=1 has already been set by Xcode.

    So you can use #if DEBUG "out of box".

    By the way, how to use the condition compilation blocks in general is written in Apple's book The Swift Programming Language 4.1 (the section Compiler Control Statements) and how to write the compile flags and what is counterpart of the C macros in Swift is written in another Apple's book Using Swift with Cocoa and Objective C (in the section Preprocessor Directives)

    Hope in future Apple will write the more detailed contents and the indexes for their books.

提交回复
热议问题