[swift-evolution] #available has a huge anti-pattern.
james at supmenow.com
Tue Feb 2 04:03:05 CST 2016
Coming from a web background (before my iOS career) to me #avaliable has
huge problem. It encourages fragility.
In my eyes we should encourage two types of detection: Features to make
code more adaptable to different environments and language version
detection: so we can understand the actual code.
See this example below:
func magic(object: Object)
Ideally for me I would love to check if the foo function exists like so:
func iOS9OnlyProtocolFunction(object: Object)
I think this encourages feature detection which results in less fragile
code. What I would love to do is also to extend this to extensions so we
could encourage polyfills.
extend object where not_avaliable(Object.foo)
//Polyfill for platforms which don't support the Object.foo method
Not sure about compiler details but being able to polyfill the function
results in much cleaner code for me. I love this approach from the web, so
I created my own Objective-C Library to do this:
*james at supmenow.com <james at supmenow.com>⎥supmenow.com <http://supmenow.com>*
*Runway East *
*10 Finsbury Square*
* EC2A 1AF *
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution