Thursday, May 12, 2016

Swift Tip: Prevent code execution using #if false and #endif

To disable several lines of code in Swift, a useful method alternative to comment characters /* and */ is to use the # (number/hash/pound) sign plus if false and endif as below:

#if false
...
....code to be disabled....
... 
#endif

For example:

print("123")
#if false
print("456")
#endif

Result:

123

No comments:

Post a Comment