NSError Challenge


Can a moderator for the Objective-C Programming Guide please respond?

Look up the NSError class reference in the developer documentation and create new NSError instances to hand back when saving and loading fails, as mentioned at the end of the chapter.

Got it and did that…

End of chapter: Notice that for the first time, you’re implementing a method that takes in an NSError**. In this case, we are merely handing back the NSError generated by propertyListWithData:options:format:error:, but you could also create and hand back a new NSError as well, depending on the nature of the failure.

I’m just seeking clarification on the challenge and i’m also making sure i’m well rounded when it comes to using NSError. Do I still need to handle outError? If yes is the code listed below the right way to deal with the errors? Do you only want us to create another NSError object and use it instead of the outError? Is there any where else in the Apple documentation you suggest we look for examples?

  • (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
    // Insert code here to read your document from the given data of the specified type. If outError != NULL, ensure that you create and set an appropriate error when returning NO.
    // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
    // If you override either of these, you should also override -isEntireFileLoaded to return NO if the contents are lazily loaded.
    // Extract our todoItems
    if (outError) {
    *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];

    NSError *theError = nil;

      todoItems = [NSPropertyListSerialization propertyListWithData:data

    if (todoItems == nil) {
    NSAlert *theAlert = [NSAlert alertWithError];
    [theAlert runModal];

    return (todoItems !=nil);