Monday, April 29, 2013

NSBundle loadAndReturnError example ios


loadAndReturnError:

Loads the bundle’s executable code and returns any errors.
- (BOOL)loadAndReturnError:(NSError **)error
Parameters
error
On input, a pointer to an error object variable. On output, this variable may contain an error object indicating why the bundle’s executable could not be loaded. If no error occurred, this parameter is left unmodified. You may specify nil for this parameter if you are not interested in the error information.
Return Value of [NSBundle loadAndReturnError]
YES if the bundle’s executable code was loaded successfully or was already loaded; otherwise, NOif the code could not be loaded.
Discussion of [NSBundle loadAndReturnError]
If this method returns NO and you pass a value for the error parameter, a suitable error object is returned in that parameter. Potential errors returned are in the Cocoa error domain and include the types that follow. For a full list of error types, see FoundationErrors.h.
  • NSFileNoSuchFileError - returned if the bundle’s executable file was not located.
  • NSExecutableNotLoadableError - returned if the bundle’s executable file exists but could not be loaded. This error is returned if the executable is not recognized as a loadable executable. It can also be returned if the executable is a PEF/CFM executable but the current process does not support that type of executable.[NSBundle loadAndReturnError]
  • NSExecutableArchitectureMismatchError - returned if the bundle executable does not include code that matches the processor architecture of the current processor.
  • NSExecutableRuntimeMismatchError - returned if the bundle’s required Objective-C runtime information is not compatible with the runtime of the current process.
  • NSExecutableLoadError - returned if the bundle’s executable failed to load for some detectable reason prior to linking. This error might occur if the bundle depends on a framework or library that is missing or if the required framework or library is not compatible with the current architecture or runtime version.[NSBundle loadAndReturnError]
  • NSExecutableLinkError - returned if the executable failed to load due to link errors but is otherwise alright.
The error object may contain additional debugging information in its description that you can use to identify the cause of the error. (This debugging information should not be displayed to the user.) You can obtain the debugging information by invoking the error object’s descriptionmethod in your code or by using the print-object command on the error object in gdb.
Example of [NSBundle loadAndReturnError]
id bundle = [NSBundle bundleWithPath:pathToBundle];
NSError *err;
if(![bundle loadAndReturnError:&err]) {
  // err contains error info
} else {
  // bundle loaded properly
  Class pluginClass = [bundle principleClass];
  // instantiate pluginClass and off you go...
}