Dictionary now gives error 'not convertible to BooleanLiteralConvertible' since updating to Swift 1.2 -
i'm getting head around swift - came swift 1.2 (breaking working code)!
i have function based on code sample nshipster - cgimagesourcecreatethumbnailatindex.
my working code is:
import imageio func processimage(jpgimagepath: string, thumbsize: cgsize) { if let path = nsbundle.mainbundle().pathforresource(jpgimagepath, oftype: "") { if let imageurl = nsurl(fileurlwithpath: path) { if let imagesource = cgimagesourcecreatewithurl(imageurl, nil) { let maxsize = max(thumbsize.width, thumbsize.height) / 2.0 let options = [ kcgimagesourcethumbnailmaxpixelsize: maxsize, kcgimagesourcecreatethumbnailfromimageifabsent: true ] let scaledimage = uiimage(cgimage: cgimagesourcecreatethumbnailatindex(imagesource, 0, options)) // other stuff } } } }
since swift 1.2, compiler provides 2 errors relating options
dictionary:
- type of expression ambiguous without more context
- '_' not convertible 'booleanliteralconvertible' (in ref 'true' value)
i have tried variety ways declare types in options dictionary (eg. [string : any]
, [cfstring : any]
, [any : any]
). while may solve 1 error, introduce other errors.
can please illuminate me?? more importantly, can please explain changed swift 1.2 , dictionaries stopped working.
from xcode 6.3 release notes:
the implicit conversions bridged objective-c classes (nsstring/nsarray/nsdictionary) corresponding swift value types (string/array/dictionary) have been removed, making swift type system simpler , more predictable.
the problem in case cfstring
s kcgimagesourcethumbnailmaxpixelsize
. these not automatically converted string
anymore. 2 possible solutions:
let options = [ kcgimagesourcethumbnailmaxpixelsize string : maxsize, kcgimagesourcecreatethumbnailfromimageifabsent string : true ]
or
let options : [nsstring : anyobject ] = [ kcgimagesourcethumbnailmaxpixelsize: maxsize, kcgimagesourcecreatethumbnailfromimageifabsent: true ]
Comments
Post a Comment