Skip to content

Instantly share code, notes, and snippets.

@0xced
Created November 15, 2017 15:40
Show Gist options
  • Save 0xced/d930df3b5e1529a576920e18f1feca9d to your computer and use it in GitHub Desktop.
Save 0xced/d930df3b5e1529a576920e18f1feca9d to your computer and use it in GitHub Desktop.
Get a *localized* string for a given HTTP status code
#import <Foundation/Foundation.h>
static NSString * _Nonnull ActuallyLocalizedStringForStatusCode(NSInteger statusCode)
{
static NSBundle *cfNetworkBundle;
static dispatch_once_t once;
dispatch_once(&once, ^{
cfNetworkBundle = [NSBundle bundleForClass:NSHTTPURLResponse.class];
});
NSString *httpError = [NSHTTPURLResponse localizedStringForStatusCode:statusCode];
return [cfNetworkBundle localizedStringForKey:httpError value:nil table:nil] ?: httpError;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment