dictionary - Creating a NSDictionary as Int:String out of an plist-file -
I have created a plist-file containing ints as in keys and string values As . Now I want to make a dictionary out of it:
path = NSBundle.mainBundle (). PathForResource ("myPlist", ofType: "plist") as dict = NSDictionary (contentoff file: path!) [Int: string]
... but the app crashes though , If I declare it as [string: string] it works but i need the key as an int.
I can not find any fault within the plist
first int
swift in a built-in cast or There is no conversion, so you must manually declare and insert a new dictionary element through
for loop:
var plist = [int: string] () For (key, value) dict {if do index = (key as? String)? ToInt () {If value is value = value? String {plist [index] = value}}}
if
ensures that the key can be converted to int
, While the second examines that the value is actually a string
.
Comments
Post a Comment