diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index a7142d0f009e1007ff5cbc4b18ddf222bf9b2408..a8cd3a0e74201b2fb8438d093456490f1d82efce 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -57,13 +57,16 @@ // Default initializer. - (instancetype)initWithAddress:(NSString *)address { + if (!address) { + return nil; + } // To provide a default port, we try to interpret the address. If it's just a host name without // scheme and without port, we'll use port 443. If it has a scheme, we pass it untouched to the C // gRPC library. // TODO(jcanizales): Add unit tests for the types of addresses we want to let pass untouched. NSURL *hostURL = [NSURL URLWithString:[@"https://" stringByAppendingString:address]]; - if (hostURL && !hostURL.port) { + if (hostURL.host && !hostURL.port) { address = [hostURL.host stringByAppendingString:@":443"]; }