Search code examples
xamarin.iosplist

How to read or write data from .plist file in Xamarin.ios


  1. Need to fetch data from plist file
  2. Need to display the data in UITableView in Xamarin.iOS

Solution

  • It's fairly trivial to read from a plist.

    Make sure the build action of the plist file is "Bundle resource".

    Then you can read the contents of the plist, if it's a dictionary:

    var dict = NSDictionary.FromFile (path);
    

    Or it's an array:

    NSArray array = NSArray.FromFile(path);
    

    From the NSArray you can populate a UITableView.

    I'd advise you check out the tutorial on Xamarin's website, for populating a UITableView, its very clear and concise.

    [1] http://developer.xamarin.com/guides/ios/user_interface/tables/part_2_-_populating_a_table_with_data/

    Edited to read from as a dictionary, per @jstedfast advice in the comment