Converting to NSDictionary
Lelelo1 opened this issue · comments
Converting to NSDictionary
Here is my current implementation
public static NSDictionary ToNSDictionary(this Dictionary<string, object> dict)
{
var nsDict = NSDictionary.FromObjectsAndKeys(dict.Values?.ToArray()
, dict.Keys.ToArray());
return nsDict;
}
However I get into trouble when having a value in Dictionary
of List<string>
and therefore I am unable send lists as a event property to Mixpanel.
Do someone have a nice implementation that supports providing list as value to NSDictionary, so it can be sent to Mixpanel?
Is sending lists supported by Mixpanel? I have not attempted to use this personally as our things are either key->string or key->int.
Yes it says list are supported.
Since I am only looking to use List<string>
for now - I think I will just make it a comma separated string. But I will test to see what happens if I put a NSArray directly into the NSDictionary
and see if it's currently possible.
nsDictionary.SetValueForKey(NSArray.FromStrings("one", "two", "three"), nsEventPropertyName)
Works and shows up in Mixpanel. Shows each element in the array has value
.. one is shown at the top of the list of values
I assume my own approach with using a single string would have it appear as one value
Oh nice! Glad you got it sorted.
I agree, a single string with commas probably would have just made it a single entry.
This does make me wonder though about things going forwards with this library. I do plan to add a Xam.Plugin.Mixpanel.Forms
where it will do the internal stuff of converting dictionaries where needed. I wonder if I should put a helper class within Xam.Plugin.Mixpanel.iOS
to handle Dict/List conversion and then the new Forms library just uses that internally.