Objective-C overwriting file alert
In my application, I want the user to be able to select a file/location to save data to. Thus, I'm using the following code:
NSSavePanel *newSavePanel = [NSSavePanel savePanel];
NSArray *newArray = [[NSArray alloc] initWithObjects:@"txt", nil]; //example file type
[newSavePanel setAllowedFileTypes:newArray];
NSInteger newInt;
newInt = [newSavePanel runModal];
My problem is that I want the save panel to alert the user and ask for confirmat开发者_如何学Pythonion to overwite if the file already exists. To do this, do I need to implement the delegate method panel:userEnteredFilename:confirmed:
in which I place a [[NSFileManager defaultManager] fileExistsAtPath:]
message, at which point I create an NSAlert, or is there a better way to go about doing this?
I haven't actually had time to test this, so if the behavior is already implemented in NSSavePanel, could someone let me know?
I may be wrong, but I think you get that behavior by default.
*edit - * yeah you get that out of the box, I used your code.
精彩评论