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 04-12-2010, 08:57 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 24
sclaxplayer is on a distinguished road
Default Create empty plist then write data to it

I'm trying to create an empty plist then write data to the plist.
What currently happens is I create an empty plist:

Code:
NSString *pathToWrite = [[NSBundle mainBundle] pathForResource:CurrentUser ofType:@"plist"]; //Current user is a NSString
if(pathToWrite == NULL) //There is no data at that location create new
{
	NSDictionary *emptyDict = [NSDictionary alloc];
	NSString *path1 = [[NSString alloc] initWithFormat:@"/Documents/%@.plist", CurrentUser];
	NSString *path2 = [[NSString alloc] initWithFormat:@"%@.plist", CurrentUser];
	[emptyDict writeToFile:path1 atomically:YES]; //I have tried both paths of 1 and 2
	NSString *pathToUserData = [[NSBundle mainBundle] pathForResource:CurrentUser ofType:@"plist"];
			
	if(pathToUserData == NULL){
		NSLog(@"NOTHING STILL!!!");
	}
	else
		NSLog(@"SUCCESS!!??");
	}
I don't get success to the final if statement show and I believe that shows nothing really happens.

Any help? Thanks
sclaxplayer is offline   Reply With Quote
Old 04-12-2010, 09:06 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Quote:
Originally Posted by Apple Documentation for pathForResource:ofType:
The method first looks for a matching resource file in the non-localized resource directory of the specified bundle. (In Mac OS X, this directory is typically called Resources but in iPhone OS, it is the main bundle directory.) If a matching resource file is not found, it then looks in the top level of any available language-specific “.lproj” directories. (The search order for the language-specific directories corresponds to the user’s preferences.) It does not recurse through other subdirectories at any of these locations. For more details see Bundles and Localization.
Your technique is not working for reading the Documents directory. And you cannot save files into the bundle.

Why are you trying to make an empty file first?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 04-12-2010, 11:38 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 24
sclaxplayer is on a distinguished road
Default

I guess I don't really need to create an empty file first.
Where should I be storing the plist if not in the Main Bundle? in Documents?
And How do I save a plist?

Would I save it with do it with:
[populatedDict writeToFileath1 atomically:YES];
sclaxplayer is offline   Reply With Quote
Old 04-13-2010, 08:14 PM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 24
sclaxplayer is on a distinguished road
Default

Figured it out:
Code:
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *path = [documentsDirectory stringByAppendingPathComponent:@"UserList.plist"];
	[Mydict writeToFile:path atomically:YES];
sclaxplayer is offline   Reply With Quote
Old 07-11-2010, 09:45 AM   #5 (permalink)
iPhoneDev
 
Join Date: Dec 2009
Posts: 33
sivasankarp is on a distinguished road
Send a message via Yahoo to sivasankarp
Default Hi BrianSlick

Hi BrianSlick


Can you guide me how to add the datas to PLISt using code.im new to iphone development .pls guide me thro any sample codes..


Thanks
sivasankarp 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: 316
15 members and 301 guests
chemistry, Domele, Fstuff, givensur, heshiming, HowEver, iAppDeveloper, iphonedevshani, jbro, JoeRCruso, kapps11, newDev, SLIC, stanny, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,874
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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