Problem: In several applications, I've found the need to pop up an alert/message window telling the application user that something went wrong, or that something they did wasn't kosher.
Solution: NSRunAlertPanel. Little macros like this one are additional reasons I love programming for the Mac. But to make it a little more useful, I created a method call that makes a dummy alert with an ok button and a given message. It looks like this:
-(void) displayAlert:(NSString*) alertMsg {
NSRunAlertPanel(@"Alert", alertMsg, @"OK", nil, nil);
}
The actual NSRunAlertPanel macro signature looks like this:
NSRunAlertPanel(NSString *title,
NSString *msgFormat,
NSString *defaultButton,
NSString *alternateButton,
NSString *otherButton)
Other parameters can be added to the method signature to create more full-featured alerts. I created the method solely to remove the NSRunAlertPanel call (which can be a big method call) from the logic of what I'm doing at the moment and replace it with a short method call that does what I want it to.