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

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Calcuccino Programmers' Calculator
($2.99)

DataFon(Build Apps on Windows)
(free)

Infinote Pinboard for Todos and Notes
(free)

picplz
(free)

poG
($2.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-27-2010, 10:31 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 3
Default Trouble Writing to pList file

I am trying to append to an array plist but have been unsuccessful. I'm not sure what I'm doing wrong. I don't get any errors but it doesn't append the test string.



PHP Code:
-(NSString *) saveFilePath
{
    
NSArray *pathArray =
    
NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);

    return [[
pathArray objectAtIndex:0stringByAppendingPathComponent:@"project.plist"];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    
NSString *myPath = [self saveFilePath];
    
NSString *test = @"Code";
    
NSMutableArray *values = [[NSMutableArray allocinitWithContentsOfFile:myPath];
        [
values addObject:test];   
        [
values writeToFile:[self saveFilePathatomically:YES];
        [
values release];

    [
super viewDidLoad];

KiKaL is offline   Reply With Quote
Old 07-27-2010, 10:54 AM   #2 (permalink)
Registered Member
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 977
Default

Oops. I was missing an allocate of the values array. Try this:


Code:
- (void)viewDidLoad {
	NSString *myPath = [self saveFilePath];
	NSString *test = @"Code";
	NSArray *fileArray = [[NSArray alloc] initWithContentsOfFile:myPath];
	NSMutableArray* values = [NSMutableArray arrayWithCapacity: [fileArray count] +1];
	[values addObjectsFromArray: fileArray];
	[fileArray release];
	[values addObject:test];   
	[values writeToFile:[self saveFilePath] atomically:YES];

	[super viewDidLoad];
}

In that code, we create a new mutable copy of the array, sizing it to hold one more object than the array read from the file.
__________________
Regards,

Duncan C
WareTo
Check out our apps in the Apple App store

Last edited by Duncan C; 07-27-2010 at 12:20 PM.
Duncan C is offline   Reply With Quote
Old 07-27-2010, 11:08 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 3
Default

Hmm seems to be a step in the right direction but now it does crash. The Console shows

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView addObjectsFromArray:]: unrecognized selector sent to instance 0x5d5e310'
KiKaL is offline   Reply With Quote
Old 07-27-2010, 12:21 PM   #4 (permalink)
Registered Member
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 977
Default

Quote:
Originally Posted by KiKaL View Post
Hmm seems to be a step in the right direction but now it does crash. The Console shows

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView addObjectsFromArray:]: unrecognized selector sent to instance 0x5d5e310'

I edited my post above to fix a bug.
__________________
Regards,

Duncan C
WareTo
Check out our apps in the Apple App store
Duncan C is offline   Reply With Quote
Old 07-27-2010, 01:15 PM   #5 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 3
Default

That seems to be close to working. It is adding the object to the Array. I know this because "Coder" is showing in the array at the position its being added. The only thing it's not doing is writing to the file.

I attached the file to see if maybe showing what I'm trying to do will help. Essentially this is a test project (just learning) To use Multiple views and save data. View1 shows a table of the pList, going to view 2 adds "coder" to the pList. Screen 3 currently does nothing.

I appreciate the help a lot

edit- just realized the attachment is to big
It can be downloaded from here

Last edited by KiKaL; 07-27-2010 at 01:22 PM.
KiKaL 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
» Stats
Members: 51,375
Threads: 52,830
Posts: 225,477
Top Poster: BrianSlick (3,576)
Welcome to our newest member, darrentousignant
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:28 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0