#if DEBUG
print("debug")
#else
print("release")
#endif
以上代碼, 在oc中, 不做任何設置是可以正常使用的, 但是在swift中, 會直接進入else. 不會走if里面.
了解后發(fā)現(xiàn)在swift中正常使用需要在build settings中額外設置
- build settings
- 搜索'swift compiler'
- 找到 swift compiler - custom flags
- 在debug下增加一個 設置anySDK flag為 -D DEBUG
swift的#if DEBUG就可以使用了.