ios - Type 'String' does not conform to protocol 'NSCopying' error when downcast AnyObject to String -


{"Key_1": {"Key_2": "value"}}

and then assign "value" to a variable

This is my code:

  var variableShouldBeAssigned: string if x = (json result ["key_1"]? As NSDictionary) {if let's do y = (x ["key_2"] ? String) {variableShouldBeAssigned = y}}  

However, when I try to downgrade from x ["key_2"] an error occurs? is fine for a string, but it is downgrading to an NSDictionary from jsonResult ["key_1"] .

I change x ["key_2"] to change x ["key_2"]? , but I do not know if it is only jsonResult [ "Key_1"]

Can anyone tell me the reason?

The string does not conform to NSCopying, but definitely NSString does! Besides, going from NSString to string is implicitly contained ...

Then I will say Try something like that ... string to NSString

O is a sample, suppose you handle jsonResult as an NSDictionary ...

  func giveDictionary (JsonResult: NSDictionary) -> string? {If let x = ( ? NSDictionary in the form of jsonResult ["key_1"] {if let's do? (NSString as x ["key_2"] {return y}} return nil}  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -