views:

154

answers:

1

I've looked through the SDK documentation and through other questions that have been asked, and I am still a little confused on how exactly to do this. I had been previously been working with the following code, though it does not give the desired result of a .plist file. Besides mentioning the IBAction in the header files in this code in the .m file, is there anything else that needs to be added or anothe method I should be taking? Thanks!

My Code:

- (IBAction)fedDog { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    NSString *documentsDirectory = [paths objectAtIndex:0];  
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dogsFedDays.plist"];   
    NSMutableArray *dogsFedSave = [NSMutableArray arrayWithCapacity: 100];  
    for (int i = 0; i < 100; i++) {  
        NSDictionary *myDict = [[NSDictionary alloc] initWithObjectsAndKeys:  
                                                        date[i], @"string", 
                                                        fed[i], @"Yes", 
                                                        nil];  
        [dogsFedSave addObject:myDict];  
        [myDict release];  
    }  
    if (![dogsFedSave writeToFile:path atomically:YES])  
        NSLog(@"not successful in completing this task");  
} 
A: 

I'm assuming that -writeToFile is returning NO so you're seeing your NSLog statement (correct me if I'm wrong). If that's the case, then the issue must be that some object in either your date array, or fed array is not any of the allowed object types for property lists which includes: NSString, NSData, NSArray, or NSDictionary. NSNulls are not allowed. From the docs for writeToFile:

This method recursively validates that all the contained objects are property list objects before writing out the file, and returns NO if all the objects are not property list objects, since the resultant file would not be a valid property list.

Matt Long