Created
November 15, 2017 15:40
-
-
Save 0xced/d930df3b5e1529a576920e18f1feca9d to your computer and use it in GitHub Desktop.
Get a *localized* string for a given HTTP status code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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