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 Enter image details here

string to 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}}}  

first if ensures that the key can be converted to int , While the second examines that the value is actually a string .


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -