how to add and retrieve data from plist programmatically
Asked Answered
C

1

8

hello all I am new to objective c and i want to insert data dynamically/programmatically into plist.please help me.Here is my plist structure

root
  |_Client1
        |_report1
             |_application1
             |_application2

        |_report2
             |_application3

  |_Client2
       |_report1

Now i want to add and retrieve data dynamically to application1,application2 in my plist please help me

Chromonema answered 15/4, 2011 at 8:10 Comment(2)
Use the NSUserDefaults instead.Mervin
You can read from a plist to a dictionary with [[NSDictionary dictionaryWithContentsOfFile:]](developer.apple.com/library/mac/documentation/Cocoa/Reference/…) and write it out using [[myDictionary writeToFile:path atomically:YES]](#3985222)Brainless
C
12

Reading content of .plist file ..

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"league" ofType:@"plist"];
contentArray = [NSArray arrayWithContentsOfFile:plistPath];

Writing to .plist file.

NSMutableDictionary * myDictionary;
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"league" ofType:@"plist"];
[myDictionary writeToFile:plistPath atomically:YES];

Note that: Dictionary must contain plist objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary). And dictionary keys must be NSString objects

Collin answered 15/4, 2011 at 8:56 Comment(1)
change "path" to "plistPath".Sustentation

© 2022 - 2024 — McMap. All rights reserved.