问题
如图,在Build Settings -> Preprocessor Macros中添加了ISADEMO=1。但在代码中判断无效,还是会输出"isn't ADemo"
swift
#if ISADEMO
print("is ADemo")
#else
print("isn't ADemo")
#endif
解决
如图,要让Preprocessor Macros定义的宏生效,还需要去Build Settings -> Other Swift Flags中标记新定义的宏,注意要用"-D"修饰。