Showing posts from February, 2016

Swift: Conditional Compilation

Debug spew is a great support mechanism for tracking workflow of your code and to augment debugging. However, leaving that support within your code is not just a poor decor for code stylists, it can also lead to security issues and occasionally to App Review Rejections. As of Swift 2.1, if all you need is just check whether the code is built with debug or release configuration, you may use the built-in functions: _isDebugAssertConfiguration()  (true when optimization is set to  -Onone ) _isReleaseAssertConfiguration()  (true when optimization is set to  -O ) _isFastAssertConfiguration()  (true when optimization is set to  -Ounchecked ) It would be used as the following example: func obtain() -> AbstractThing {    if _isDebugAssertConfiguration () {        return DecoratedThingWithDebugInformation(Thing())    } else {        return Thing()    } } Compared with preprocessor macros, ✓ You don’t need to define a custom  -D DEBUG  flag to use it ~ It is actually defi

Controlling your WEMO switches

WEMO  switches might don’t need an introduction. If you haven’t them sooner or later, you will. It’s just matter of time. In a nutshell, they are IoT devices that allow you from your smartphone or other smart means to turn on and off lights from anywhere. At their core, they are UPNP devices. Which means knowing their protocol and syntax to make the calls you can interact with the devices via anything that you can code with. Today I choose Node JS. If the work UPNP sounds foreign to you then here is your cue: Universal Plug and Play ( UPnP ) is a networking technology used to discover devices and services on a network.  Chances are, if you have any sort of device on your home network it is probably a device that understands UPnP.  UPnP uses HTTP over UDP, SOAP, and XML for performing its various interactions.  Finding a device involves sending out a discovery packet (using  SSDP ) to a multicast address and waiting for responses.  Within the response, a device description and