xcode - #ifdef replacement in the Swift language -
in c/c++/objective-c can define macro using compiler preprocessors. moreover, can include/exclude parts of code using compiler preprocessors.
#ifdef debug // debug-only code #endif
is there similar solution in swift?
yes can it.
in swift can still use "#if/#else/#endif" preprocessor macros (although more constrained), per apple docs. here's example:
#if debug let = 2 #else let = 3 #endif
now, must set "debug" symbol elsewhere, though. set in "swift compiler - custom flags" section, "other swift flags" line. add debug symbol -d debug
entry.
as usual, can set different value when in debug or when in release.
i tested in real code , works; doesn't seem recognized in playground though.
you can read original post here.
important note: -ddebug=1
doesn't work. -d debug
works. seems compiler ignoring flag specific value.
Comments
Post a Comment