One Quickie


#if 0 in Swift (Swift->Hacks)
Have a bunch of code to temporarily chop out because of reasons? In C you could use #if 0 to tear out chunk of your file.

#if in Swift generally requires the guts of the conditional to be syntactically correct (even if it's semantically nonsense).

You can abuse the Swift version check to do something similar to #if 0:

     ...
#if swift(>=666)
    aj2n42j4n23jnjsdnfjsnfjnunrun unr unwu nudjfn jsnf jn
    var window: UIWindow?
#endif
   ...
The compiler still does some processing of the code, so you might get an error (like if that cat-stomp at the beginning started with a digit, Swift tries interpreting 2n42j4n23jnjsdnfjsnfjnunrun as an integer literal and fails)

(Thanks to Jeremy Sherman for the idea)



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com