Reputation: 307
I am trying to convert a Dictionary to NSDictionary.
document = NSDictionary\<string, object\>(); // with some data of course
The way I am doing this is:
NSDictionary<NSString, NSObject> iosDoc = NSDictionary<NSString, NSObject>.FromObjectsAndKeys(
document.Values.ToArray(),
document.Keys.ToArray()
);
And the error I get is the following:
Error CS1061: 'Dictionary<string, object>.ValueCollection' does not contain a definition for 'ToArray' and no accessible extension method 'ToArray' accepting a first argument of type 'Dictionary<string, object>.ValueCollection' could be found (are you missing a using directive or an assembly reference?) (CS1061)
Error CS1061: 'Dictionary<string, object>.KeyCollection' does not contain a definition for 'ToArray' and no accessible extension method 'ToArray' accepting a first argument of type 'Dictionary<string, object>.KeyCollection' could be found (are you missing a using directive or an assembly reference?) (CS1061)
This has worked in a previous project and Visual Studio recognises this method but the code doesn't compile.
Any ideas?
Upvotes: 1
Views: 129
Reputation: 10938
If you want to convert from Dictionary
to NSDictionary
, you could try the code below. It works well for me. I tested on ios 15.4 with xcode 13.3.
var document = new Dictionary<string, string>
{
{"A", "a"},
{"B", "b"},
{"C", "c"},
{"D", "d"},
{"E", "e"}
};
var iosDoc = NSDictionary.FromObjectsAndKeys(document.Values.ToArray(), document.Keys.ToArray());
Upvotes: 2