casting - New warning in Xcode 6.3 & Swift 1.2: Cast from '[SKNode]' to unrelated type 'String' always fails -


after updating xcode 6.3 / swift 1.2 have run error can't resolve: "cast '[sknode]' unrelated type 'string' fails".

below gamescene code begins parsing p-list.

import spritekit  class gamescene: skscene, skphysicscontactdelegate, nsxmlparserdelegate {      var currenttmxfile:string?      override func didmovetoview(view: skview) {          /* parse p-list */          let path = nsbundle.mainbundle().pathforresource("gamedata", oftype: "plist")         let dict = nsdictionary(contentsoffile: path!)!         let playerdict:anyobject = dict.objectforkey("playersettings")!         let gamedict:anyobject = dict.objectforkey("gamesettings")!         let levelarray:anyobject = dict.objectforkey("levelsettings")!          if let levelnsarray:nsarray = levelarray as? nsarray {              var leveldict:anyobject = levelnsarray[level]              numberoflevels = levelnsarray.count              if let tmxfile = leveldict["tmxfile"] as? string {                  currenttmxfile = tmxfile              }          } 

the error being thrown at...

if let tmxfile = leveldict["tmxfile"] as? string {... 

and returning nil value, though there string value in p-list , prior updating, working fine. have tried casting anyobject first , throws more errors.

here:

var leveldict:anyobject = levelnsarray[level] 

you declaring leveldict anyobject, here:

if let tmxfile = leveldict["tmxfile"] as? string { 

you using if dictionary - wonder how it's possible worked in previous version of xcode...

however, fix it, make variable explicit dictionary, either cocoa one:

var leveldict = levelnsarray[level] as? nsdictionary  if let tmxfile = leveldict?.objectforkey("tmxfile") as? string { 

or swift one:

var leveldict = levelnsarray[level] as? [string : anyobject]  if let tmxfile = leveldict?["tmxfile"] as? string { 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -