Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.iOS, convert Dictionary to NSDictionary

Am trying to integrate Branch.io in my Xamarin project and came across this requirement to convert c#'s Dictionary to NSDictionary.

Tried

  • dictionary as NSDictionary //Didn't work

Tried this as well

private NSMutableDictionary BranchData (Dictionary<string, object> data)
        {
            List<string> keys = data.Keys.ToList();
            NSMutableDictionary branchData = new NSMutableDictionary ();

            foreach (string key in keys) {
                branchData.Add (new NSString(key), data[key] as NSObject);
            }
            return branchData;
        }

Didn't work.

Any leads would be helpful. Thanks!

UPDATE:

https://stackoverflow.com/a/5664785/344798

like image 539
coder284 Avatar asked Mar 16 '16 05:03

coder284


1 Answers

This is how i converted a dictionary to an NSDictionary

var iconattrs = new Dictionary<string, string>
                {
                    {"ITEMTYPE", "DIVESITE"},
                    {"LOCATION", diveSite.Location},
                    {"DESCRIPTION", diveSite.BriefDescription},
                    {"LINK", diveSite.Link},
                    {"ID", diveSite.ID.ToString()}
                };

 var myResult = NSDictionary.FromObjectsAndKeys(iconattrs.Values.ToArray()
                                               ,iconattrs.Keys.ToArray())
like image 95
InitLipton Avatar answered Sep 24 '22 16:09

InitLipton