<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Joe —<br></div>
<div> </div>
<div>Is this intended to be a supported behavior? I was all excited the other day to discover this behavior, using it to backport iOS 9's NSLayoutConstraint DSL. It mostly works, but as soon as an expression gets relatively complex (array literals >5 or so) or has any sort of error in it, Swift falls back to reporting an availability error.<br></div>
<div> </div>
<div id="sig40804545"><div class="signature">Zach Waldowski<br></div>
<div class="signature"><a href="mailto:zach@waldowski.me">zach@waldowski.me</a><br></div>
<div> </div>
</div>
<div>On Tue, Feb 2, 2016, at 11:26 AM, Joe Groff via swift-evolution wrote:<br></div>
<blockquote type="cite"><div>Polyfills have their own tradeoffs; they tend to encourage constant accretion of glue code as new versions get added if there's no pressure to drop old versions, leading to a significant amount of the multi-megabyte Javascript framework downloads we all complain about these days. That said, you might be able to use the related `@available` attribute to introduce backfill extensions that are only available on older systems.<br></div>
<div> </div>
<div><div>-Joe<br></div>
<div><div> </div>
<div><blockquote type="cite"><div>On Feb 2, 2016, at 2:03 AM, James Campbell via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div>
<div> </div>
<div><div dir="ltr"><div>Coming from a web background (before my iOS career) to me #avaliable has huge problem. It encourages fragility.<br></div>
<div> </div>
<div>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.<br></div>
<div> </div>
<div>See this example below:<br></div>
<div> </div>
<div>func magic(object: Object)<br></div>
<div>{<br></div>
<div> if(#avaliable(9.0, 10))<br></div>
<div> {<br></div>
<div> object.foo()<br></div>
<div> }<br></div>
<div>}<br></div>
<div> </div>
<div>Ideally for me I would love to check if the foo function exists like so:<br></div>
<div> </div>
<div><div>func iOS9OnlyProtocolFunction(object: Object)<br></div>
<div>{<br></div>
<div> if(#avaliable(Object.foo))<br></div>
<div> {<br></div>
<div> object.foo()<br></div>
<div> }<br></div>
<div>else <br></div>
<div>{<br></div>
<div> object.baz()<br></div>
<div> }<br></div>
<div>}<br></div>
<div> </div>
<div>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.<br></div>
<div> </div>
<div>extend object where not_avaliable(Object.foo) <br></div>
<div>{<br></div>
<div> func foo() <br></div>
<div> {<br></div>
<div> //Polyfill for platforms which don't support the Object.foo method<br></div>
<div> }<br></div>
<div>}<br></div>
<div> </div>
<div>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:<br></div>
<div> </div>
<div><a href="https://github.com/jcampbell05/Polly">https://github.com/jcampbell05/Polly</a><br></div>
<div><div><div dir="ltr"><div><div dir="ltr"><p><b><span class="colour" style="color:rgb(204, 0, 0)">___________________________________</span></b><br></p><p><b>James⎥Lead Engineer</b><br></p><p><b><span class="colour" style="color:rgb(204, 0, 0)"><a href="mailto:james@supmenow.com">james@supmenow.com</a>⎥<a href="http://supmenow.com/">supmenow.com</a></span></b><br></p><p><b><span class="size" style="font-size:small">Sup</span></b><br></p><p><b><span class="size" style="font-size:small">Runway East
</span></b><br></p><p><b><span class="size" style="font-size:small">10 Finsbury Square</span></b><br></p><p><b><span class="size" style="font-size:small">London</span></b><br></p><p><b><span class="size" style="font-size:small">
EC2A 1AF </span></b><br></p></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>_______________________________________________<br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div>https://lists.swift.org/mailman/listinfo/swift-evolution<br></div>
</div>
</blockquote></div>
</div>
</div>
<div><u>_______________________________________________</u><br></div>
<div>swift-evolution mailing list<br></div>
<div><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br></div>
<div><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div>
</blockquote><div> </div>
</body>
</html>