Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is NSAlert.h in the iOS SDK?

Tags:

ios

iphone

According to iOS's Using and Creating Error Objects, one can display a error object with the following code.

NSError *theError = nil;
BOOL success = [myDoc writeToURL:[self docURL] ofType:@"html" error:&theError];

if (success == NO) {
    // Maybe try to determine cause of error and recover first.
    NSAlert *theAlert = [NSAlert alertWithError:theError];
    [theAlert runModal]; // Ignore return value.
}

Unfortunately, I am not smart enough to figure out how to include NSAlert.h.

Any help would be appreciated.

like image 781
jww Avatar asked Apr 12 '11 14:04

jww


2 Answers

That document is referring to the (OS X) AppKit framework. Right after that box, it says:

(UIAlertView, the UIKit class corresponding to NSAlert, has no equivalent method for alertWithError:.)

You can still use UIAlertView, but you'll need to manually populate the title, message, and button strings from the error.

like image 92
Daniel Dickison Avatar answered Nov 03 '22 22:11

Daniel Dickison


NSAlert isn't availble in UIKit. the example it just an copy past of the OS X doc.

This code in Listing 2-1 uses the returned NSError to display an error alert to the user immediately. (UIAlertView, the UIKit class corresponding to NSAlert, has no equivalent method for alertWithError:.) Error objects in the Cocoa domain are always localized and ready to present to users, so they can often be presented without further evaluation.

like image 37
rckoenes Avatar answered Nov 03 '22 20:11

rckoenes