-1
 `-(IBAction)saveData
    {
        //get paths from root directory
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,        /*   */  NSUserDomainMask, YES);

//get documents path
        NSString *documentsPath = [paths objectAtIndex:0];

//get the path to our Data/plist file
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];


//set the variables to the values in the text fields
        self.personName = nameEntered.text;
        self.phoneNumbers = [[NSMutableArray alloc] initWithCapacity:3];
        [phoneNumbers addObject:myPhone.text];
        [phoneNumbers addObject:momPhone.text];
        [phoneNumbers addObject:dadPhone.text];

        //create dictionary with values in UITextFields
        NSDictionary *plistDict = [NSDictionary dictionaryWithObjects: 
[NSArray arrayWithObjects: personName, phoneNumbers, nil] forKeys:
[NSArray arrayWithObjects: @"Name", @"Phones", nil]];

        NSString *error = nil;
        //create NSData from dictionary
        NSData *plistData = [NSPropertyListSerialization dataFromPropertyList: plistDict             /* */   format: NSPropertyListXMLFormat_v1_0 errorDescription: &error];

    //check if plist data exists
    if (plistData)
    {
        //write plistData to our Data.plist file
        [plistData writeToFile:plistPath atomically: YES];            
    }
    else
    {
        NSLog(@"Error in saveData: %@", error);
        [error release];
    }
}`

I can not find the error with the -(IBAction). It says there is an expected expression. Any help would be greatly appreciated! I am new to coding so I do not know much.

I fixed it guys, thanks for all the help. It was a big rookie mistake I made... I put my actions inside the viewdidload :(

Just_chillin
  • 39
  • 1
  • 8
  • 1
    Please format the code more nicely. . . SO will detect code if you use four spaces. . . (which is why only some of the above is) . . then we can see what is going on. – Jasper Blues Jan 14 '13 at 02:10
  • 3
    _where_ does it complain? – foundry Jan 14 '13 at 02:16
  • The most likely reason is an unclosed curly brace above the code from your post. – Sergey Kalinichenko Jan 14 '13 at 02:16
  • @user1975244, aside from automatically/atomically I cannot find any errors in your code now.. please mark on which line it is complaining `expected expression` – foundry Jan 14 '13 at 02:57
  • @Zaph, I think you mean 'that is automatic' ;-j – foundry Jan 14 '13 at 03:05
  • 1
    @user1975244 your would be well served to find a tutorial that is more up-to-date in the conventions used. These days it is not necessary to either declare ivars nor to synthesize them, that is now automatic. – zaph Jan 14 '13 at 03:07
  • @He, thanks, auto-correct gets me sometimes. :-) not -> now. – zaph Jan 14 '13 at 03:08

2 Answers2

0

This:

         [plistData writeToFile:plistPath automatically: YES];            

should be this:

         [plistData writeToFile:plistPath atomically: YES];            

(mind you, that wouldn't give you the 'expected expression' error, you should see a 'no interface for NSData declares the selector...' type error...)

foundry
  • 31,615
  • 9
  • 90
  • 125
  • I changed it to atomically, but it didn't fix it. thank you for spotting that error though too haha. I'd post a picture so it'd be easier to see, but this site won't let new members do that. – Just_chillin Jan 14 '13 at 02:30
  • you could post a link to a picture.. – foundry Jan 14 '13 at 02:32
  • If it helps, this is the tutorial I am trying to follow http://www.theappcodeblog.com/2011/05/30/property-list-tutorial-using-plist-to-store-user-data/ – Just_chillin Jan 14 '13 at 02:39
  • @Zaph - fixed, thanks ...it's becoming a [massive pet peev of mine](http://stackoverflow.com/questions/14236799/should-i-declare-variables-in-interface-or-using-property-in-objective-c-arc/14236931#14236931) when people intermix iVar and property -referencing conventions... – foundry Jan 14 '13 at 02:49
  • @Zaph - agreed, i've just deleted my comment – foundry Jan 14 '13 at 02:55
  • @Zaph - going going gone... – foundry Jan 14 '13 at 02:59
0

For starters the methods names are incorrect
Wrong:

[plistData writetoFile:plistPath automatically: YES]; 

Correct:

[plistData writeToFile:plistPath atomically:YES];

From Apple docs:

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
zaph
  • 111,848
  • 21
  • 189
  • 228