Skip to content

Instantly share code, notes, and snippets.

@zoul
Created October 19, 2010 08:21
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save zoul/633827 to your computer and use it in GitHub Desktop.
Save zoul/633827 to your computer and use it in GitHub Desktop.
Decode OSStatus error codes into strings.
NSString *NSStringFromOSStatus(OSStatus errCode)
{
if (errCode == noErr)
return @"noErr";
char message[5] = {0};
*(UInt32*) message = CFSwapInt32HostToBig(errCode);
return [NSString stringWithCString:message encoding:NSASCIIStringEncoding];
}
@revolc
Copy link

revolc commented Apr 26, 2013

gr8t!

@ShonFrazier
Copy link

(NSString *) CreateTypeStringWithOSType(OSType inType); // ;-)

@talha131
Copy link

In macOS easier way is to use SecCopyErrorMessageString.

NSString *errorMessage = [((NSString *)SecCopyErrorMessageString(errCode, NULL))autorelease];

@egormerkushev
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment