[swift-evolution] Thoughts on "Fully eliminate implicit bridging conversions from Swift"

simon gladman sgladman at gmail.com
Tue May 24 11:07:45 CDT 2016


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, *Fully
eliminate implicit bridging conversions from Swift*.

First off, rightly or wrongly, I've always typed the scalar parameters of
my subclassed *CIFilters* as *CGFloat*. It makes working with *CIVectors*
and *CGRects* cleaner and feels more "Swifty" than using *NSNumber*.
However, moving to Swift 3.0, using anything apart from an *NSNumber*
breaks. For example:

        let radius: CGFloat = 25



        let blur = CIFilter(

            name: "CIGaussianBlur",

            withInputParameters: [kCIInputRadiusKey: radius])

The same with passing arguments to a *CIKernel*, *CIWarpKernel* or
*CIColorKernel*:

        kernel.apply(

            withExtent: CGRect(x: 0, y: 0, width: 100, height: 100),

            arguments: [radius])

Secondly, the attributes property of a filter (of type *[String: AnyObject]*)
which I'd normally code along the lines of:

    override var attributes: [String : AnyObject]

    {

        return [

            "inputImage": [

                 kCIAttributeIdentity: 0,

                 kCIAttributeClass: "CIImage",

                 kCIAttributeDisplayName: "Image",

                 kCIAttributeType: kCIAttributeTypeScalar]

        ]

    }

...fails to compile. kCIAttributeTypeScalar is of type *String* and needs
to be cast to *NSString* and the dictionary itself needs to be cast to
*AnyObject*:

    override var attributes: [String : AnyObject]

    {

        return [

            "inputImage": [

                 kCIAttributeIdentity: 0,

                 kCIAttributeClass: "CIImage",

                 kCIAttributeDisplayName: "Image",

                 kCIAttributeType: kCIAttributeTypeScalar as NSString] as
AnyObject

        ]

    }

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.

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?

Any thoughts would be greatly appreciated!

Simon


Simon Gladman     +44 7973 669691

Blog: http://flexmonkey.blogspot.co.uk
GitHub: https://github.com/FlexMonkey
Twitter: @FlexMonkey <https://twitter.com/FlexMonkey>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160524/8d1e6f12/attachment.html>


More information about the swift-evolution mailing list