[swift-users] Swift 3 Questions
Austin Zheng
austinzheng at gmail.com
Mon May 23 02:46:40 CDT 2016
Hi Simon,
This behavior is intentional; implicit bridging conversions are slated for removal in Swift 3.
More information: https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md <https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md>
Best,
Austin
> On May 23, 2016, at 12:44 AM, simon gladman via swift-users <swift-users at swift.org> wrote:
>
> Hi All,
>
> I thought I'd attempt updating the code of my Filterpedia <https://github.com/FlexMonkey/Filterpedia> 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?
>
> First off, overriding CIFilter requires overriding the attributes var which is of type [String: AnyObject]. In Swift 2, the following works perfectly:
>
> override var attributes: [String : AnyObject] {
> return [
> kCIAttributeFilterDisplayName: "CMYK Levels",
> "inputImage": [kCIAttributeIdentity: 0,
> kCIAttributeClass: "CIImage",
> kCIAttributeDisplayName: "Image",
> kCIAttributeType: kCIAttributeTypeImage]
> ]
> }
>
> 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:
>
> override var attributes: [String : AnyObject] {
> return [
> kCIAttributeFilterDisplayName: "CMYK Levels",
> "inputImage": [kCIAttributeIdentity: 0,
> kCIAttributeClass: "CIImage",
> kCIAttributeDisplayName: "Image",
> kCIAttributeType: kCIAttributeTypeImage as AnyObject] as AnyObject
> ]
> }
>
> There's a similar casting issue with the arguments parameter of a kernel's apply method. In Swift 2, the following compiles without issue:
>
> let kernel = CIColorKernel()
>
> let rect = CGRect(
> x: 0, y: 0,
> width: 100, height: 100)
>
> let inputRadius: CGFloat = 5.678
> let inputCenter = CIVector(x: 12.3, y: 45.6)
> let inputRect = CIVector(cgRect: rect)
> let inputString = "Xyzzy"
>
> let arguments = [inputRect,
> inputRadius,
> inputCenter,
> inputString]
>
> kernel.apply(
> withExtent: rect,
> arguments: arguments)
>
> While in 3, I need to do the following:
>
> let arguments = [inputRect,
> inputRadius as AnyObject,
> inputCenter,
> inputString as AnyObject] as [AnyObject]
>
> Any thoughts anybody?
>
> Cheers!
>
> Simon
>
> Simon Gladman +44 7973 669691 <tel:%2B44%207973%20669691>
>
> Blog: http://flexmonkey.blogspot.co.uk <http://flexmonkey.blogspot.co.uk/>
> GitHub: https://github.com/FlexMonkey <https://github.com/FlexMonkey>
> Twitter: @FlexMonkey <https://twitter.com/FlexMonkey>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160523/69414e0b/attachment.html>
More information about the swift-users
mailing list