Saturday 15 May 2010

iOS 8 Swift Read Plist -



iOS 8 Swift Read Plist -

i want read values plist file integers. have next code:

let path = nsbundle.mainbundle().pathforresource("savedstate", oftype: "plist") allow dict = nsdictionary(contentsoffile: path!) allow players: anyobject = string(dict.valueforkey("players") nsstring) allow level: anyobject = string(dict.valueforkey("level") nsstring) allow numplayers = int(players nsnumber) allow playlevel = int(level nsnumber)

the allow players: , allow level: crash app. know should simple - can't figure out how it.

you may looking this:

let path = nsbundle.mainbundle().pathforresource("savedstate", oftype: "plist") allow dict = nsdictionary(contentsoffile: path!) allow players = dict.valueforkey("players") as? string allow level = dict.valueforkey("level") as? string allow numplayers = players != nil ? players!.toint() : 0 allow playlevel = level != nil ? level!.toint() : 0

it attempts read players , level plist optional strings, if non nil sets numplayers , playlevel int value. if nil numplayers , playlevel set 0. although if plist values integers, why not read them ints?

let players = dict.valueforkey("players") as? int allow level = dict.valueforkey("level") as? int

ios swift plist

No comments:

Post a Comment