Get GRPC compiling with `-Woverriding-method-mismatch` (#28215)

pull/28222/head
dmaclach 3 years ago committed by GitHub
parent cce34f68b7
commit 9e3b364ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      src/objective-c/GRPCClient/private/GRPCCore/GRPCRequestHeaders.m

@ -22,11 +22,18 @@
#import "NSDictionary+GRPC.h" #import "NSDictionary+GRPC.h"
static void CheckIsNilOrString(NSString *name, id value) {
if (value && ![value isKindOfClass:[NSString class]]) {
[NSException raise:NSInvalidArgumentException format:@"%@ must be an NSString", name];
}
}
// Used by the setter. // Used by the setter.
static void CheckIsNonNilASCII(NSString *name, NSString *value) { static void CheckIsNonNilASCIIString(NSString *name, id value) {
if (!value) { if (!value) {
[NSException raise:NSInvalidArgumentException format:@"%@ cannot be nil", name]; [NSException raise:NSInvalidArgumentException format:@"%@ cannot be nil", name];
} }
CheckIsNilOrString(name, value);
if (![value canBeConvertedToEncoding:NSASCIIStringEncoding]) { if (![value canBeConvertedToEncoding:NSASCIIStringEncoding]) {
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
format:@"%@ %@ contains non-ASCII characters", name, value]; format:@"%@ %@ contains non-ASCII characters", name, value];
@ -49,7 +56,7 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) {
@"instead got %@", @"instead got %@",
key, value]; key, value];
} }
CheckIsNonNilASCII(@"Text header value", (NSString *)value); CheckIsNonNilASCIIString(@"Text header value", value);
} }
} }
@ -100,20 +107,24 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) {
} }
} }
- (id)objectForKey:(NSString *)key { - (id)objectForKey:(id)key {
return _delegate[key.lowercaseString]; CheckIsNilOrString(@"Header name", key);
NSString *stringKey = [(NSString *)key lowercaseString];
return _delegate[stringKey];
} }
- (void)setObject:(id)obj forKey:(NSString *)key { - (void)setObject:(id)obj forKey:(id<NSCopying>)key {
CheckIsNonNilASCII(@"Header name", key); CheckIsNonNilASCIIString(@"Header name", key);
key = key.lowercaseString; NSString *stringKey = [(NSString *)key lowercaseString];
CheckKeyValuePairIsValid(key, obj); CheckKeyValuePairIsValid(stringKey, obj);
_delegate[key] = obj; _delegate[stringKey] = obj;
} }
- (void)removeObjectForKey:(NSString *)key { - (void)removeObjectForKey:(id)key {
CheckIsNilOrString(@"Header name", key);
NSString *stringKey = [(NSString *)key lowercaseString];
[self checkCallIsNotStarted]; [self checkCallIsNotStarted];
[_delegate removeObjectForKey:key.lowercaseString]; [_delegate removeObjectForKey:stringKey];
} }
- (NSUInteger)count { - (NSUInteger)count {

Loading…
Cancel
Save