apple maps - openMapsWithItems cannot Invoke with argument list issue in Swift 2.0 -
i'm having few issues converting swift 1.2 code 2.0 - 1 of issues.
i have function opens ios maps app give directions location. working fine until conversion. following error message:
cannot invoke 'openmapswithitems' argument list of type '([mkmapitem], launchoptions: [nsobject : anyobject])'
this code (the error appears on last line):
func openmapswithdirections(longitude:double, latitude:double, placename:string){ var coordinate = cllocationcoordinate2dmake(cllocationdegrees(longitude), cllocationdegrees(latitude)) var placemark:mkplacemark = mkplacemark(coordinate: coordinate, addressdictionary:nil) var mapitem:mkmapitem = mkmapitem(placemark: placemark) mapitem.name = placename let launchoptions:nsdictionary = nsdictionary(object: mklaunchoptionsdirectionsmodedriving, forkey: mklaunchoptionsdirectionsmodekey) var currentlocationmapitem:mkmapitem = mkmapitem.mapitemforcurrentlocation() mkmapitem.openmapswithitems([currentlocationmapitem, mapitem], launchoptions: launchoptions [nsobject : anyobject]) }
any ideas? thanks.
as can seen in the pre-release developer resources mkmapitem, openmapswithitems:launchoptions:
has changed taking [nsobject : anyobject]!
taking [string : anyobject]?
, have declare (or cast) such.
change in code line
let launchoptions:nsdictionary = nsdictionary(object: mklaunchoptionsdirectionsmodedriving, forkey: mklaunchoptionsdirectionsmodekey)
to
let launchoptions = [mklaunchoptionsdirectionsmodekey: mklaunchoptionsdirectionsmodedriving]
and last line
mkmapitem.openmapswithitems([currentlocationmapitem, mapitem], launchoptions: launchoptions [nsobject : anyobject])
to
mkmapitem.openmapswithitems([currentlocationmapitem, mapitem], launchoptions: launchoptions)
that should work.
sidenote: should change code style allow swift infer types. please stop hurting everyone's eyes var placemark:mkplacemark = mkplacemark(...)
. try avoid nsdictionary
, please use swift's dictionary
Comments
Post a Comment