<div dir="ltr"><div>Apologies for arriving a little late to the party and I hope this is a suitable forum to discuss this subject. I've spent some time over the last few days moving a large Core Image project to Swift 3.0 and come across some side effects which I think are related to proposal SE-0072, <i>Fully eliminate implicit bridging conversions from Swift</i>.</div><div><br></div><div>First off, rightly or wrongly, I've always typed the scalar parameters of my subclassed <i>CIFilters</i> as <i>CGFloat</i>. It makes working with <i>CIVectors</i> and <i>CGRects</i> cleaner and feels more "Swifty" than using <i>NSNumber</i>. However, moving to Swift 3.0, using anything apart from an <i>NSNumber</i> breaks. For example:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(4,51,255)">let</span><span style=""> radius: </span><span style="color:rgb(52,149,175)">CGFloat</span><span style=""> = 25</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style=""> </span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(4,51,255)">let</span><span style=""> blur = </span><span style="color:rgb(52,149,175)">CIFilter</span><span style="">(</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> name: </span><span style="color:rgb(180,38,26)">"CIGaussianBlur"</span><span style="">,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> withInputParameters: [</span><span style="color:rgb(52,149,175)">kCIInputRadiusKey</span><span style="">: radius])</span></p></div><div><br></div><div>The same with passing arguments to a <i>CIKernel</i>, <i>CIWarpKernel</i> or <i>CIColorKernel</i>:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> kernel.</span><span style="color:rgb(52,149,175)">apply</span><span style="">(</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> withExtent: </span><span style="color:rgb(52,149,175)">CGRect</span><span style="">(x: 0, y: 0, width: 100, height: 100)</span>,</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> arguments: [radius])</span></p></div><div><br></div><div>Secondly, the attributes property of a filter (of type <i>[String: AnyObject]</i>) which I'd normally code along the lines of:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(4,51,255)">override</span><span style=""> </span><span style="color:rgb(4,51,255)">var</span><span style=""> attributes: [</span><span style="color:rgb(52,149,175)">String</span><span style=""> : </span><span style="color:rgb(52,149,175)">AnyObject</span><span style="">]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(4,51,255)">return</span><span style=""> [</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(180,38,26)">"inputImage"</span><span style="">: [</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(52,149,175)">kCIAttributeIdentity</span><span style="">: 0,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(52,149,175)">kCIAttributeClass</span><span style="">: </span><span style="color:rgb(180,38,26)">"CIImage"</span><span style="">,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,149,175)"><span style="color:rgb(0,0,0)"> </span><span style="">kCIAttributeDisplayName</span><span style="color:rgb(0,0,0)">: </span><span style="color:rgb(180,38,26)">"Image"</span><span style="color:rgb(0,0,0)">,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,149,175)"><span style="color:rgb(0,0,0)"> </span><span style="">kCIAttributeType</span><span style="color:rgb(0,0,0)">: </span><span style="">kCIAttributeTypeScalar</span><span style="color:rgb(0,0,0)">]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> ]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> }</span></p></div><div><br></div><div>...fails to compile. <span style="font-family:Menlo;font-size:11px">kCIAttributeTypeScalar </span>is of type <i>String</i> and needs to be cast to <i>NSString</i> and the dictionary itself needs to be cast to <i>AnyObject</i>:</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(4,51,255)">override </span><span style="color:rgb(4,51,255)">var</span> attributes: [<span style="color:rgb(52,149,175)">String</span> : <span style="color:rgb(52,149,175)">AnyObject</span>]</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(4,51,255)">return</span><span style=""> [</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(180,38,26)">"inputImage"</span><span style="">: [</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(52,149,175)">kCIAttributeIdentity</span><span style="">: 0,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(52,149,175)">kCIAttributeClass</span><span style="">: </span><span style="color:rgb(180,38,26)">"CIImage"</span><span style="">,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,149,175)"><span style="color:rgb(0,0,0)"> </span><span style="">kCIAttributeDisplayName</span><span style="color:rgb(0,0,0)">: </span><span style="color:rgb(180,38,26)">"Image"</span><span style="color:rgb(0,0,0)">,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,149,175)"><span style="color:rgb(0,0,0)"> </span><span style="">kCIAttributeType</span><span style="color:rgb(0,0,0)">: </span><span style="">kCIAttributeTypeScalar</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(4,51,255)">as</span><span style="color:rgb(0,0,0)"> </span><span style="">NSString</span><span style="color:rgb(0,0,0)">] </span><span style="color:rgb(4,51,255)">as</span><span style="color:rgb(0,0,0)"> </span><span style="">AnyObject</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> ]</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> }</span></p></div><div><br></div><div>It seems awkward to me that the constant supplied by Core Image to describe an attribute's type needs to be cast to another type to get it working. </div><div><br></div><div>Are these changes just something that we'll need to live with? Are they still in flux? Have I totally misunderstood everything and there's a more elegant solution?</div><div><br></div><div>Any thoughts would be greatly appreciated!</div><div><br></div><div>Simon</div><div><br></div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div style="text-align:center"></div><div style="text-align:center"><div style="color:rgb(0,0,0);text-align:start;word-wrap:break-word">Simon Gladman <a href="tel:%2B44%207973%20669691" value="+447973669691" style="color:rgb(17,85,204)" target="_blank">+44 7973 669691</a></div><div style="color:rgb(0,0,0);text-align:start;word-wrap:break-word"><br>Blog: <a href="http://flexmonkey.blogspot.co.uk/" style="color:rgb(17,85,204)" target="_blank">http://flexmonkey.blogspot.co.uk</a><br>GitHub: <a href="https://github.com/FlexMonkey" style="color:rgb(17,85,204)" target="_blank">https://github.com/FlexMonkey</a></div><div style="color:rgb(0,0,0);text-align:start;word-wrap:break-word">Twitter: <a href="https://twitter.com/FlexMonkey" style="color:rgb(17,85,204)" target="_blank">@FlexMonkey</a></div></div><br></div></div></div></div></div>
</div>