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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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, 11: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, 11:54 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,749
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


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.

Last edited by Duncan C; 07-27-2010 at 01:20 PM.
Duncan C is offline   Reply With Quote
Old 07-27-2010, 12:08 PM   #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, 01:21 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,749
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


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 07-27-2010, 02: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 02: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: 157,864
Threads: 88,915
Posts: 379,298
Top Poster: BrianSlick (7,072)
Welcome to our newest member, MediaSolutions
Powered by vBadvanced CMPS v3.1.0

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