sensible nullability annotation for old API

pull/16190/head
Muxi Yan 6 years ago
parent 70f34521de
commit 76f1ec16e1
  1. 22
      src/objective-c/GRPCClient/GRPCCall.h
  2. 7
      src/objective-c/GRPCClient/GRPCCall.m
  3. 10
      src/objective-c/ProtoRPC/ProtoRPC.h
  4. 10
      src/objective-c/examples/SwiftSample/ViewController.swift

@ -282,6 +282,8 @@ NS_ASSUME_NONNULL_END
*/
@interface GRPCCall : GRXWriter
- (instancetype)init NS_UNAVAILABLE;
/**
* The container of the request headers of an RPC conforms to this protocol, which is a subset of
* NSMutableDictionary's interface. It will become a NSMutableDictionary later on.
@ -306,7 +308,7 @@ NS_ASSUME_NONNULL_END
*
* The property is initialized to an empty NSMutableDictionary.
*/
@property(nullable, atomic, readonly) NSMutableDictionary *requestHeaders;
@property(nonnull, atomic, readonly) NSMutableDictionary *requestHeaders;
/**
* This dictionary is populated with the HTTP headers received from the server. This happens before
@ -339,9 +341,9 @@ NS_ASSUME_NONNULL_END
* host parameter should not contain the scheme (http:// or https://), only the name or IP addr
* and the port number, for example @"localhost:5050".
*/
- (nullable instancetype)initWithHost:(nullable NSString *)host
path:(nullable NSString *)path
requestsWriter:(nullable GRXWriter *)requestWriter;
- (nullable instancetype)initWithHost:(nonnull NSString *)host
path:(nonnull NSString *)path
requestsWriter:(nonnull GRXWriter *)requestWriter;
/**
* Finishes the request side of this call, notifies the server that the RPC should be cancelled, and
@ -353,11 +355,11 @@ NS_ASSUME_NONNULL_END
* The following methods are deprecated.
*/
+ (void)setCallSafety:(GRPCCallSafety)callSafety
host:(nullable NSString *)host
path:(nullable NSString *)path;
host:(nonnull NSString *)host
path:(nonnull NSString *)path;
@property(nullable, atomic, copy, readwrite) NSString *serverName;
@property NSTimeInterval timeout;
- (void)setResponseDispatchQueue:(nullable dispatch_queue_t)queue;
- (void)setResponseDispatchQueue:(nonnull dispatch_queue_t)queue;
@end
@ -368,11 +370,11 @@ DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.")
@protocol GRPCRequestHeaders<NSObject>
@property(nonatomic, readonly) NSUInteger count;
- (nullable id)objectForKeyedSubscript:(nullable id)key;
- (void)setObject:(nullable id)obj forKeyedSubscript:(nullable id)key;
- (nullable id)objectForKeyedSubscript:(nonnull id)key;
- (void)setObject:(nullable id)obj forKeyedSubscript:(nonnull id)key;
- (void)removeAllObjects;
- (void)removeObjectForKey:(nullable id)key;
- (void)removeObjectForKey:(nonnull id)key;
@end
#pragma clang diagnostic push

@ -445,6 +445,9 @@ const char *kCFStreamVarName = "grpc_cfstream";
}
+ (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path {
if (host.length == 0 || path.length == 0) {
return;
}
NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path];
switch (callSafety) {
case GRPCCallSafetyDefault:
@ -466,10 +469,6 @@ const char *kCFStreamVarName = "grpc_cfstream";
return [callFlags[hostAndPath] intValue];
}
- (instancetype)init {
return [self initWithHost:nil path:nil requestsWriter:nil];
}
// Designated initializer
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path

@ -142,11 +142,11 @@ __attribute__((deprecated("Please use GRPCProtoCall."))) @interface ProtoRPC
* addr and the port number, for example @"localhost:5050".
*/
-
(nullable instancetype)initWithHost : (nullable NSString *)host method
: (nullable GRPCProtoMethod *)method requestsWriter
: (nullable GRXWriter *)requestsWriter responseClass
: (nullable Class)responseClass responsesWriteable
: (nullable id<GRXWriteable>)responsesWriteable NS_DESIGNATED_INITIALIZER;
(nullable instancetype)initWithHost : (nonnull NSString *)host method
: (nonnull GRPCProtoMethod *)method requestsWriter
: (nonnull GRXWriter *)requestsWriter responseClass
: (nonnull Class)responseClass responsesWriteable
: (nonnull id<GRXWriteable>)responsesWriteable NS_DESIGNATED_INITIALIZER;
- (void)start;
@end

@ -54,8 +54,8 @@ class ViewController: UIViewController {
} else {
NSLog("2. Finished with error: \(error!)")
}
NSLog("2. Response headers: \(RPC.responseHeaders)")
NSLog("2. Response trailers: \(RPC.responseTrailers)")
NSLog("2. Response headers: \(String(describing: RPC.responseHeaders))")
NSLog("2. Response trailers: \(String(describing: RPC.responseTrailers))")
}
// TODO(jcanizales): Revert to using subscript syntax once XCode 8 is released.
@ -68,7 +68,7 @@ class ViewController: UIViewController {
let method = GRPCProtoMethod(package: "grpc.testing", service: "TestService", method: "UnaryCall")!
let requestsWriter = GRXWriter(value: request.data())
let requestsWriter = GRXWriter(value: request.data())!
let call = GRPCCall(host: RemoteHost, path: method.httpPath, requestsWriter: requestsWriter)!
@ -80,8 +80,8 @@ class ViewController: UIViewController {
} else {
NSLog("3. Finished with error: \(error!)")
}
NSLog("3. Response headers: \(call.responseHeaders)")
NSLog("3. Response trailers: \(call.responseTrailers)")
NSLog("3. Response headers: \(String(describing: call.responseHeaders))")
NSLog("3. Response trailers: \(String(describing: call.responseTrailers))")
})
}
}

Loading…
Cancel
Save