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 09-11-2010, 08:23 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 79
ramdas is on a distinguished road
Smile usage of plist - any disadvantages?

Hello,
I had asked a qestion whether I should use a Plist here :
http://www.iphonedevsdk.com/forum/ip...tml#post244057

Thanks for the response

I have still decided to make use of PList

Here is what I have coded :

Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES );
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *fileWithPath = [documentsDirectory stringByAppendingPathComponent:@"appConfig.plist"];

// I then check if the file exists 
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fileWithPath];

//if this file does not exist then I know user has just installed the application 
//so I create the file and store some flag in it 
if (!(fileExists)){
		
NSString *firstTimeFlag = @"TRUE";
NSMutableArray *appConfigArray = [[NSMutableArray arrayWithCapacity:1] retain];
NSArray *keys = [NSArray arrayWithObjects:@"firstTimeFlag",nil];
		[appConfigArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:firstTimeFlag,nil] forKeys:keys]];

[appConfigArray writeToFile:fileWithPath atomically:YES];
This I can do

My questions are - I see that this file gets created in a wierd location :
/users / <<user >> / Library / Application Support / iPhone Simulator / 4.0.2 / applications / <<some no >> / Documents / appConfig.plist


When I reset the simulator the file is gone
Whiich is fine
when I restart the application ( without resetting the simulator) - I can detect the file which is what I want

I am wondering to maintain state this way - will it also work on iPhone

I also plan to save the state that user has logged in a application this way
Is there any thing I should be worried about ?
Will this work on iPhone or only on simulator ?

I see apple is really taking pains to make developers to go through loops
Which is how I guess they generate revenue ( already spent about usd 2500 in INdian rupees to buy an iphone and a macbook )
The frustrating thing is I will have to spend another usd 100 to register
and then too ( which I will post a separate thread) I see that I dont quite uunderstand how to do an ad hoc deployment on my phone

Anyway that is going to be a separate question for you guys here !

Please let me know your thoughts - and thanks
~ramdas
ramdas is offline   Reply With Quote
Old 09-11-2010, 08:57 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by ramdas View Post
Hello,
I had asked a qestion whether I should use a Plist here :
http://www.iphonedevsdk.com/forum/ip...tml#post244057

Thanks for the response

I have still decided to make use of PList

Here is what I have coded :

Code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES );
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *fileWithPath = [documentsDirectory stringByAppendingPathComponent:@"appConfig.plist"];

// I then check if the file exists 
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fileWithPath];

//if this file does not exist then I know user has just installed the application 
//so I create the file and store some flag in it 
if (!(fileExists)){
		
NSString *firstTimeFlag = @"TRUE";
NSMutableArray *appConfigArray = [[NSMutableArray arrayWithCapacity:1] retain];
NSArray *keys = [NSArray arrayWithObjects:@"firstTimeFlag",nil];
		[appConfigArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:firstTimeFlag,nil] forKeys:keys]];

[appConfigArray writeToFile:fileWithPath atomically:YES];
This I can do

My questions are - I see that this file gets created in a wierd location :
/users / <<user >> / Library / Application Support / iPhone Simulator / 4.0.2 / applications / <<some no >> / Documents / appConfig.plist


When I reset the simulator the file is gone
Whiich is fine
when I restart the application ( without resetting the simulator) - I can detect the file which is what I want

I am wondering to maintain state this way - will it also work on iPhone

I also plan to save the state that user has logged in a application this way
Is there any thing I should be worried about ?
Will this work on iPhone or only on simulator ?

I see apple is really taking pains to make developers to go through loops
Which is how I guess they generate revenue ( already spent about usd 2500 in INdian rupees to buy an iphone and a macbook )
The frustrating thing is I will have to spend another usd 100 to register
and then too ( which I will post a separate thread) I see that I dont quite uunderstand how to do an ad hoc deployment on my phone

Anyway that is going to be a separate question for you guys here !

Please let me know your thoughts - and thanks
~ramdas
What you are doing will work, on both the iPhone and the simulator, but you are going to a lot of work to duplicate the features of NSUserDefaults.

NSUserDefaults is a specialized dictionary of objects that saves settings that you need to keep between launches. You can use it to store fairly complex structures.

NSUserDefaults includes the ability to specify initial values for any key, using the call registerDefaults. That creates starting values for a set of keys. If you later write a new value for a given key the starting value is then overridden by the new value.

A number of the sample apps included with the iPhone SDK use this method of storing settings, including using registerDefaults to save default values. The "Metronome" sample app is a simple example. Do a search on "Metronome" in the XCode help system to find it, and take a look at the project.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-11-2010, 09:14 AM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 79
ramdas is on a distinguished road
Default

Thanks Duncan for the response
I will look into what you have suggested and make changes
Atleast it is a relief to know that this will work ( though does not seem to be the best / most efficient way to use existing objects )
I guess that is the trouble of trying to get some urgent delivery done without even knowing the basics of XCode .....
( I am a Java developer and am really having a tough time with apple and iphone )

Once again thanks for pointing me in the right direction !
ramdas 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: 345
12 members and 333 guests
bignoggins, carlandrews, cgokey, givensur, hzwegjxg, ilmman, jenniead38, linkmx, mraalex, PixelInteractive, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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