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:

  1. type of expression ambiguous without more context
  2. '_' 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 cfstrings 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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -