I’ve been spending way too long trying to figure out what is going wrong, so I hope someone her can help me out.
My Code:
- (IBAction)fedDog {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"dogsFedDays.plist"];
NSMutableArray *dogsFedSave = [[NSMutableArray alloc] arrayWithCapacity: 48];
for (int i = 0; i < 48; 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");
}
I’ve connected the action to a button, but when the button is pressed, the simulator freezes, and no file appears in the Documents directory.
It’s possible that the simulator freezes because of an unhandled exception. Check the debug console while your app is running.
The most probable reason your application hangs is that the button pressed may be calling
fedDog:method. Try changing your method signature to this one: