Not finding property list

Discussion in 'iOS Programming' started by larswik, Dec 31, 2011.

  1. larswik macrumors 68000

    Sep 8, 2006
    I have been bug searching the whole day and I found the problem but I don't know what is causing it. I have an IF statement that it skips since it can't find the property list. Upon entering a new viewController I have it read in the property list
    - (void)viewWillAppear:(BOOL)animated
        if (clientContentArray) { //test line to find problem
            clientContentArray = nil;
        [self readPlist];
        [super viewWillAppear:animated];
    I have one Method that creates the path to the file
    - (NSString *) dataFilePath
        NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [path objectAtIndex:0];
        return [documentsDirectory stringByAppendingPathComponent:@"clientList.plist"];
    Now in the next code I have the line • if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) • Looks like the IF statement is returning a FALSE since it is not running the code under it or printing the NSLog test that I set up. I have been cleaning up my code and moving things around so something go messed up, it was working fine last night. Does this code look right, or am I missing something?

    - (void)readPlist{
        NSString *filePath = [self dataFilePath];
        if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
            NSLog(@"I saw it");
            clientContentArray = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
            clientListForTable = [[NSMutableArray alloc] init];
            client = [[NSMutableDictionary alloc]init];        
            if ([clientContentArray count] != 0) {
                NSSortDescriptor *firstDescriptor = [[NSSortDescriptor alloc] initWithKey:@"clientNames" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
                [clientContentArray sortUsingDescriptors:[NSArray arrayWithObject:firstDescriptor]];
                for (int i = 0; i < clientContentArray.count;  i++) {
                    NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] initWithDictionary:[clientContentArray objectAtIndex:i]];
                    [clientListForTable addObject:[tempDict objectForKey:@"clientNames"]];
        [self.tableView reloadData];
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Debugging Rule #5: When the unexpected happens, show what you expected.

    This rule applies to posting, but it's also one of the 10 basic rules of debugging. If you expected to see a file, print the full pathname of the file you expected to see. If you expected an input to happen, print what you got and what you expected.

    Debugging Rule #3: Show interesting values.

    Your NSLog shows nothing interesting. The filePath is something I'd consider interesting.

    Worse, you have no 'else' part, so if the file doesn't exist, you have no useful information about what pathname it was expecting to find.
  3. larswik thread starter macrumors 68000

    Sep 8, 2006
    And that was the problem. Such a simple thing that cost me the better part of a day. While doing a little rewriting and debugging I removed the 'else' so it never wrote the file in the first place. I get so into problem solving that I forget to stop, step back, and look at the bigger picture.

    Thanks Chown33

Share This Page