ios - How to cast Dictionary in Swift to related type? -


this trying dictionary:

    if let deliveries = dictionary["deliveries"] as? nsdictionary {          var casteddeliveries = [double: double]()          delivery in deliveries {              if let value = delivery.value as? double {                 casteddeliveries[double(delivery.key as! nsnumber)] = value //could not cast value of type 'nstaggedpointerstring' (0x1a1e3af20) 'nsnumber' (0x1a1e458b0).             }         }         settings!.deliveries = casteddeliveries     } 

and try cast, part of json response server:

deliveries =            {     2 = 0;     5 = "2.59";     7 = "3.59"; }; 

it doesnt work, because there error @ commented line:

could not cast value of type 'nstaggedpointerstring' (0x1a1e3af20) 'nsnumber' (0x1a1e458b0).

you trying cast dictionary directly instead need cast each key - value pair. if want generic solution problem take @ swiftyjson library address json parsing problem you.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -