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 07-07-2010, 01:31 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 8
BradSite is on a distinguished road
Default Problem with saving plist

Hi Guys

I'm having a little trouble with my application being able to create a plist and load the information from that plist in the ViewDidLoad section. The code i'm using at the moment to check for the original file and if it is not there create one is as follows

(void)viewDidLoad {

BOOL success;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"CustomChecklist.p list"];

success = [fileManager fileExistsAtPath:filePath];
NSLog(@"STATUS OF SUCCESS %@",success);
if (!success) {
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingFormat:@"OriginalChecklist.plist"];
success = [fileManager copyItemAtPathath toPath:filePath];
self.dataArray = [NSMutableArray arrayWithContentsOfFile:filePath];
NSLog(@"IF STATEMENT CREATING THE FILE");
}else {
self.dataArray = [NSMutableArray arrayWithContentsOfFile:filePath];
NSLog(@"IF STATEMENT READING THE FILE");
}

NSLog(@"location information %@", filePath);
[super viewDidLoad];

}

When I build this application it builds and runs ok but I get a couple of warnings

NSFileManager may not respond to -copyItemAtPath:toPath

Once this has completed the output to the console looks as though it hasn't even checked for the file or created the one to read from.

2010-07-06 16:22:42.803 CampingChecklist[400:207] STATUS OF SUCCESS (null) 2010-07-06 16:22:42.805 CampingChecklist[400:207] IF STATEMENT READING THE FILE 2010-07-06 16:22:42.814 CampingChecklist[400:207] location information /Users/Brad/Library/Application Support/iPhone Simulator/3.1.3/Applications/E7074D5A-3E7A-4D2E-9F92-82B1A04873F8/Documents/CustomChecklist.plist

And obviously as there is nothing in the file, when it tries to save on the way out of the application it doesn't create any file in the path specified.

If anyone can shed any light on this problem then I would much appreciate it.

Thanks Brad
BradSite is offline   Reply With Quote
Old 07-07-2010, 02:17 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 1,018
Tambourin is on a distinguished road
Default

change it like this:
success = [fileManager copyItemAtPathath toPath:filePath error:NULL];

and since success is a scalar variable:
NSLog(@"STATUS OF SUCCESS %d",success);
Tambourin is offline   Reply With Quote
Old 07-07-2010, 07:28 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 8
BradSite is on a distinguished road
Default Problem Saving the Loaded Data

Hi Tambourin

Thanks for the post resolved the issue with it loading the data now, but i now have another issue with it saving the correct data.

I'm having problems saving the changed data back to the plist which is created at the start of the application, it loads information in to the tableview correctly but when i select a few items and then switch to another the view so the viewWillDisapear is triggered it only saves the default values from the array and not the modified ones.

I have checked the log and i can see the values changing but the output plist only shows original values.

Console output of selected item:
2010-07-07 09:20:16.519 CampingChecklist[546:207] Dump from checked row {
cell = <UITableViewCell: 0x394d280; frame = (0 0; 320 44); text = 'Water Bottle'; autoresize = W; layer = <CALayer: 0x394d590>>;
checked = 1;
text = "Water Bottle";
}

Output of Array just before saving:
2010-07-07 09:20:19.503 CampingChecklist[546:207] dataAray contents := (
{
cell = <UITableViewCell: 0x394d280; frame = (0 0; 320 44); text = 'Water Bottle'; autoresize = W; layer = <CALayer: 0x394d590>>;
checked = 1;
text = "Water Bottle";
},
{
cell = <UITableViewCell: 0x394dff0; frame = (0 44; 320 44); text = 'Bumbag'; autoresize = W; layer = <CALayer: 0x394dc80>>;
checked = 1;
text = Bumbag;
},
{
cell = <UITableViewCell: 0x394ef40; frame = (0 88; 320 44); text = 'GPS'; autoresize = W; layer = <CALayer: 0x394ea40>>;
checked = 0;
text = GPS;
},
{
cell = <UITableViewCell: 0x394f4f0; frame = (0 132; 320 44); text = 'Map'; autoresize = W; layer = <CALayer: 0x394f280>>;
checked = 0;
text = Map;
},
{
cell = <UITableViewCell: 0x394e2a0; frame = (0 176; 320 44); text = 'Compass'; autoresize = W; layer = <CALayer: 0x394f5a0>>;
checked = 0;
text = Compass;
},
{
cell = <UITableViewCell: 0x394fae0; frame = (0 220; 320 44); text = 'Backpack'; autoresize = W; layer = <CALayer: 0x394f800>>;
checked = 0;
text = Backpack;
},
etc …….

as you can see the values have changed in this list that is generated on exit but when i browse to the directory where it will be stored the contents of the plist are not the new values but the standard loaded values from the default plist.

I have also tried just loading them straight from the Bundle and then saving the array to the plist to make sure that it is saving the current data and it does the same thing and just saves the original default values not the changed information.

{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savePath = [documentsDirectory stringByAppendingPathComponent:@"CustomChecklist.p list"];
NSLog(@"View Will Disappear SAVE location information %@", savePath);
[dataArray writeToFile:savePath atomically:YES];
NSLog(@"dataAray contents := %@", dataArray);
}

any ideas please.

Thanks
Brad
BradSite is offline   Reply With Quote
Reply

Bookmarks

Tags
array, development, iphone, plist, saving

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: 337
8 members and 329 guests
bignoggins, Chickenrig, firecall, givensur, iNet, michaelhansen, Objective Zero, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,893
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 12:32 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0