[swift-users] Swift 3 Questions
    simon gladman 
    sgladman at gmail.com
       
    Mon May 23 02:44:00 CDT 2016
    
    
  
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
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-users/attachments/20160523/374262d3/attachment.html>
    
    
More information about the swift-users
mailing list