<div dir="ltr"><div>Hi All,</div><div><br></div><div>I thought I&#39;d attempt updating the code of my <a href="https://github.com/FlexMonkey/Filterpedia">Filterpedia</a> app to Swift 3. The transition has been pretty smooth so far, but I have a few issues. I guess my question over these issues is, are they features or bugs in an early Swift 3 release?</div><div><br></div><div>First off, overriding CIFilter requires overriding the <i>attributes</i> var which is of type <i>[String: AnyObject</i>]. In Swift 2, the following works perfectly:</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><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;color:rgb(52,149,175)"><span style="color:rgb(0,0,0)">                   </span><span style="">kCIAttributeFilterDisplayName</span><span style="color:rgb(0,0,0)">: </span><span style="color:rgb(180,38,26)">&quot;CMYK Levels&quot;</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><span style="color:rgb(180,38,26)">&quot;inputImage&quot;</span><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)">&quot;CIImage&quot;</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)">kCIAttributeDisplayName</span><span style="">: </span><span style="color:rgb(180,38,26)">&quot;Image&quot;</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)">kCIAttributeType</span><span style="">: </span><span style="color:rgb(52,149,175)">kCIAttributeTypeImage</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></p></div><div><br></div><div>However, because the inputImage dictionary entry is a dictionary itself and kCIAttributeTypeImage is a string, in Swift 3, it appears I have to explicitly case them to compile:</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><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;color:rgb(52,149,175)"><span style="color:rgb(0,0,0)">                   </span><span style="">kCIAttributeFilterDisplayName</span><span style="color:rgb(0,0,0)">: </span><span style="color:rgb(180,38,26)">&quot;CMYK Levels&quot;</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><span style="color:rgb(180,38,26)">&quot;inputImage&quot;</span><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)">&quot;CIImage&quot;</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)">kCIAttributeDisplayName</span><span style="">: </span><span style="color:rgb(180,38,26)">&quot;Image&quot;</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="">kCIAttributeType</span><span style="color:rgb(0,0,0)">: </span><span style="">kCIAttributeTypeImage</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><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>There&#39;s a similar casting issue with the <i>arguments</i> parameter of a kernel&#39;s <i>apply</i> method. In Swift 2, the following compiles without issue:</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=""> kernel = </span><span style="color:rgb(52,149,175)">CIColorKernel</span><span style="">()</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=""> rect = </span><span style="color:rgb(52,149,175)">CGRect</span><span style="">(</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">            x: 0, y: 0,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">            width: 100, height: 100)</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=""> inputRadius: </span><span style="color:rgb(52,149,175)">CGFloat</span><span style=""> = 5.678</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=""> inputCenter = </span><span style="color:rgb(52,149,175)">CIVector</span><span style="">(x: 12.3, y: 45.6)</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=""> inputRect = </span><span style="color:rgb(52,149,175)">CIVector</span><span style="">(cgRect: rect)</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=""> inputString = </span><span style="color:rgb(180,38,26)">&quot;Xyzzy&quot;</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=""> arguments = [inputRect,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">                         inputRadius,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">                         inputCenter,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">                         inputString]</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="">        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: rect,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">            arguments: arguments)</span></p></div><div><br></div><div>While in 3, I need to do the following:</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=""> arguments = [inputRect,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">                         inputRadius </span><span style="color:rgb(4,51,255)">as</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="">                         inputCenter,</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="">                         inputString </span><span style="color:rgb(4,51,255)">as</span><span style=""> </span><span style="color:rgb(52,149,175)">AnyObject</span><span style="">] </span><span style="color:rgb(4,51,255)">as</span><span style=""> [</span><span style="color:rgb(52,149,175)">AnyObject</span><span style="">]</span></p></div><div><br></div><div>Any thoughts anybody?</div><div><br></div><div>Cheers!</div><div><br></div><div>Simon</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>