Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-04-2010, 08:47 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: hyderabad
Posts: 29
ravi.m@tekmunk.com is on a distinguished road
Send a message via Skype™ to ravi.m@tekmunk.com
Default writing data to plist?

hi all,
i am new to iphone applications,i am reading the data from plist and when i click the button the data should be write in to the plist data.
here my problem is to write the data into the value field under income array .and totalsalary.

here is my plist data:

<?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">
<plist version="1.0">
<dict>
<key>income</key>
<array>
<dict>
<key>title</key>
<string>Salary</string>
<key>value</key> //here i have to write the data into value
<integer>0</integer>
</dict>
<dict>
<key>title</key>
<string>Bonus</string>
<key>value</key> //here i have to write the data into value
<integer>0</integer>
</dict>
<dict>
<key>title</key>
<string>Rent</string>
<key>value</key> //here i have to write the data into value
<integer>0</integer>
</dict>
<dict>
<key>title</key>
<string>Miscellenious</string>
<key>value</key> //here i have to write the data into value
<integer>0</integer>
</dict>
</array>
<key>categories</key>
<array>
<dict>
<key>title</key>
<string>Shopping</string>
<key>items</key>
<array>
<string>forClothes</string>
<string>forThings</string>
<string>miscellenious</string>
</array>
</dict>
<dict>
<key>title</key>
<string>Food</string>
<key>items</key>
<array>
<string>inRestarent</string>
<string>outSide</string>
<string>miscellanious</string>
</array>
</dict>
<dict>
<key>title</key>
<string>Householdings</string>
<key>items</key>
<array>
<string>Rent</string>
<string>Current</string>
<string>miscellenious</string>
</array>
</dict>
<dict>
<key>title</key>
<string>Health</string>
<key>items</key>
<array>
<string>hospital</string>
<string>medicine</string>
<string>miscellenious</string>
</array>
</dict>
</array>
<key>totalsalary</key> //here i have to write the data into value
<integer>0</integer>
</dict>
</plist>

thanks,
ravi.

Last edited by ravi.m@tekmunk.com; 08-04-2010 at 08:52 AM. Reason: i forget the comments
ravi.m@tekmunk.com is offline   Reply With Quote
Old 08-04-2010, 11:44 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

If the plist is an existing plist included with your app, it is put into a directory that you cannot write to. So you will have to write code to read the data and rewrite it to a different file in a different directory. Once that is done once, then you should read and write from that new writable file.

There are lots of tutorials out there with the exact code you can check out

But here is my code all in my App Delegate. kDataFile is the name of my writable file

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {		
	NSFileManager *fileManager = [NSFileManager defaultManager];
	
	NSString *filePath = [NSString stringWithFormat:@"%@/%@.%@", [self getFilePath], kDataFileName, @".plist"]; 
	if (![fileManager fileExistsAtPath:filePath]) {
		NSBundle *bundle = [NSBundle mainBundle];
		filePath = [bundle pathForResource:kDataFileName ofType:@"plist"];
	}
	self.dataInPList = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

...
}
Code:
- (void)applicationWillTerminate:(UIApplication *)application {
	// Save data if appropriate
	NSString *filePath = [NSString stringWithFormat:@"%@/%@.%@", [self getFilePath], kDataFileName, @".plist"]; 
	[dataInPList writeToFile:filePath atomically:YES];
}

- (NSString *)getFilePath {	
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	return documentsDirectory;
}
Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Old 08-07-2010, 08:15 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 3
ddot is on a distinguished road
Default help saviing to plist plss

hi guys, i am trying to save data to the plist in my app per person, but it save it to everyone, so for example if i have a field for eye color and i enter brown in the textfield for john doe, it save brown for everyone else as well, is there a way to save this info per person in the app instead using plist, i have had no luck trying

thanks
ddot is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 331
8 members and 323 guests
alexP, gordo26, headkaze, mistergreen2011, nobstudio, rayjeong, Sloshmonster, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:21 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0