views:

54

answers:

2

HI can u send me sample code to add the data to the .plist. .my plist was in this format as follows.kindly help me out

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
<array>
<string>http://localhost:8888/sample&lt;/string&gt;
<string>http://localhost:8888/sample&lt;/string&gt;
</array>
</plist>

i wil send the url string from the implementation code.kindly help me in this pls..

-(IBAction)AddFieldid)sender;
{
NSMutableArray *myPrimaryinfo = [[NSMutableArray arrayWithCapacity:6]retain];

NSArray *keys = [NSArray arrayWithObjects:@"string",nil];

[myPrimaryinfo addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:
[NSString stringWithFormat:@"sample"],nil]forKeys:keys]];


NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"urls.plist"];
[myPrimaryinfo writeToFile:path atomically:NO];
NSLog(@"PrimaryInfo array: %@", myPrimaryinfo);
}

Thanks

A: 

Hi

Can any one say me how to add the data to the PLIST using the xcode.dynamically to my xxxx.plist file.

Thanks

siva
A: 

I guess something like this would work (not very good at iphone stuff):

// Loading
NSString *path = ...
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];

// Manipulating
NSObject *newElement = ...
[array addObject:newElement];

// Storing
[array writeToFile:path atomically:YES];

By pressing "ALT" + double clicking on a class name opens up the docu for this class along with a list of methods and so on. Take a look there, too!

ZeissS
I have tried this Zeiss,but its not writing any content to the plist can u get me any sample code for that so that i can check where im making mistake
siva
use the debugger or the output to check that you have actually loaded the right file. The best example code I have is above.
ZeissS
i have tried the same code Zeiss.but the problem is in Plist its not getting saved,tats y? i asked the sample code for that to chk the Plist and its structure
siva
I don't understand a word. If you use the virtual pod, you should be able to see the saved .plist file under `Library/App.. Support/iPhone Simulator` somewhere. Otherwise, you could use a NSLabel to show the content of your array.
ZeissS
ya but some of the post they are saying tat we cant save the plist in to the device .can u recheck and tel me Zeiss please
siva
Afaik, your app can only write into your sandbox. Make sure the path points at a file in your sandbox.
ZeissS