clang-format

pull/21316/head
Muxi Yan 5 years ago
parent 264d71be4c
commit c0b85e5a46
  1. 71
      examples/objective-c/route_guide/ViewControllers.m

@ -36,8 +36,8 @@ static NSString * const kHostAddress = @"localhost:50051";
- (NSString *)description {
NSString *verticalDirection = self.latitude >= 0 ? @"N" : @"S";
NSString *horizontalDirection = self.longitude >= 0 ? @"E" : @"W";
return [NSString stringWithFormat:@"%.02f%@ %.02f%@",
abs(self.latitude) / 1E7f, verticalDirection,
return
[NSString stringWithFormat:@"%.02f%@ %.02f%@", abs(self.latitude) / 1E7f, verticalDirection,
abs(self.longitude) / 1E7f, horizontalDirection];
}
@end
@ -61,7 +61,6 @@ static NSString * const kHostAddress = @"localhost:50051";
}
@end
#pragma mark Demo: Get Feature
/**
@ -82,15 +81,19 @@ static NSString * const kHostAddress = @"localhost:50051";
void (^handler)(RTGFeature *response, NSError *error) = ^(RTGFeature *response, NSError *error) {
// TODO(makdharma): Remove boilerplate by consolidating into one log function.
if (response.name.length) {
NSString *str =[NSString stringWithFormat:@"%@\nFound feature called %@ at %@.", self.outputLabel.text, response.location, response.name];
NSString *str =
[NSString stringWithFormat:@"%@\nFound feature called %@ at %@.", self.outputLabel.text,
response.location, response.name];
self.outputLabel.text = str;
NSLog(@"Found feature called %@ at %@.", response.name, response.location);
} else if (response) {
NSString *str =[NSString stringWithFormat:@"%@\nFound no features at %@", self.outputLabel.text,response.location];
NSString *str = [NSString stringWithFormat:@"%@\nFound no features at %@",
self.outputLabel.text, response.location];
self.outputLabel.text = str;
NSLog(@"Found no features at %@", response.location);
} else {
NSString *str =[NSString stringWithFormat:@"%@\nRPC error: %@", self.outputLabel.text, error];
NSString *str =
[NSString stringWithFormat:@"%@\nRPC error: %@", self.outputLabel.text, error];
self.outputLabel.text = str;
NSLog(@"RPC error: %@", error);
}
@ -100,15 +103,18 @@ static NSString * const kHostAddress = @"localhost:50051";
point.latitude = 409146138;
point.longitude = -746188906;
GRPCUnaryProtoCall *call = [_service getFeatureWithMessage:point
responseHandler:[[GRPCUnaryResponseHandler alloc] initWithResponseHandler:handler responseDispatchQueue:nil]
GRPCUnaryProtoCall *call = [_service
getFeatureWithMessage:point
responseHandler:[[GRPCUnaryResponseHandler alloc] initWithResponseHandler:handler
responseDispatchQueue:nil]
callOptions:nil];
[call start];
call = [_service getFeatureWithMessage:[RTGPoint message]
responseHandler:[[GRPCUnaryResponseHandler alloc] initWithResponseHandler:handler responseDispatchQueue:nil]
call = [_service
getFeatureWithMessage:[RTGPoint message]
responseHandler:[[GRPCUnaryResponseHandler alloc] initWithResponseHandler:handler
responseDispatchQueue:nil]
callOptions:nil];
[call start];
}
- (void)viewDidLoad {
@ -129,7 +135,6 @@ static NSString * const kHostAddress = @"localhost:50051";
@end
#pragma mark Demo: List Features
/**
@ -167,7 +172,9 @@ static NSString * const kHostAddress = @"localhost:50051";
- (void)didReceiveProtoMessage:(GPBMessage *)message {
RTGFeature *response = (RTGFeature *)message;
if (response) {
NSString *str =[NSString stringWithFormat:@"%@\nFound feature at %@ called %@.", self.outputLabel.text, response.location, response.name];
NSString *str =
[NSString stringWithFormat:@"%@\nFound feature at %@ called %@.", self.outputLabel.text,
response.location, response.name];
self.outputLabel.text = str;
NSLog(@"Found feature at %@ called %@.", response.location, response.name);
}
@ -217,11 +224,12 @@ static NSString * const kHostAddress = @"localhost:50051";
}
- (void)execRequest {
NSString *dataBasePath = [NSBundle.mainBundle pathForResource:@"route_guide_db"
ofType:@"json"];
NSString *dataBasePath = [NSBundle.mainBundle pathForResource:@"route_guide_db" ofType:@"json"];
NSData *dataBaseContent = [NSData dataWithContentsOfFile:dataBasePath];
NSError *error;
NSArray *features = [NSJSONSerialization JSONObjectWithData:dataBaseContent options:0 error:&error];
NSArray *features = [NSJSONSerialization JSONObjectWithData:dataBaseContent
options:0
error:&error];
if (error) {
NSLog(@"Error reading database.");
@ -230,10 +238,11 @@ static NSString * const kHostAddress = @"localhost:50051";
return;
}
void (^handler)(RTGRouteSummary *response, NSError *error) = ^(RTGRouteSummary *response, NSError *error) {
void (^handler)(RTGRouteSummary *response, NSError *error) =
^(RTGRouteSummary *response, NSError *error) {
if (response) {
NSString *str =[NSString stringWithFormat:
@"%@\nFinished trip with %i points\nPassed %i features\n"
NSString *str = [NSString
stringWithFormat:@"%@\nFinished trip with %i points\nPassed %i features\n"
"Travelled %i meters\nIt took %i seconds",
self.outputLabel.text, response.pointCount, response.featureCount,
response.distance, response.elapsedTime];
@ -243,13 +252,16 @@ static NSString * const kHostAddress = @"localhost:50051";
NSLog(@"Travelled %i meters", response.distance);
NSLog(@"It took %i seconds", response.elapsedTime);
} else {
NSString *str =[NSString stringWithFormat:@"%@\nRPC error: %@", self.outputLabel.text, error];
NSString *str =
[NSString stringWithFormat:@"%@\nRPC error: %@", self.outputLabel.text, error];
self.outputLabel.text = str;
NSLog(@"RPC error: %@", error);
}
};
GRPCStreamingProtoCall *call = [_service recordRouteWithResponseHandler:[[GRPCUnaryResponseHandler alloc] initWithResponseHandler:handler
GRPCStreamingProtoCall *call =
[_service recordRouteWithResponseHandler:[[GRPCUnaryResponseHandler alloc]
initWithResponseHandler:handler
responseDispatchQueue:nil]
callOptions:nil];
[call start];
@ -257,7 +269,8 @@ static NSString * const kHostAddress = @"localhost:50051";
RTGPoint *location = [RTGPoint message];
location.longitude = [((NSNumber *)feature[@"location"][@"longitude"]) intValue];
location.latitude = [((NSNumber *)feature[@"location"][@"latitude"]) intValue];
NSString *str =[NSString stringWithFormat:@"%@\nVisiting point %@", self.outputLabel.text, location];
NSString *str =
[NSString stringWithFormat:@"%@\nVisiting point %@", self.outputLabel.text, location];
self.outputLabel.text = str;
NSLog(@"Visiting point %@", location);
[call writeMessage:location];
@ -283,7 +296,6 @@ static NSString * const kHostAddress = @"localhost:50051";
@end
#pragma mark Demo: Route Chat
/**
@ -305,13 +317,14 @@ static NSString * const kHostAddress = @"localhost:50051";
}
- (void)execRequest {
NSArray *notes = @[[RTGRouteNote noteWithMessage:@"First message" latitude:0 longitude:0],
NSArray *notes = @[
[RTGRouteNote noteWithMessage:@"First message" latitude:0 longitude:0],
[RTGRouteNote noteWithMessage:@"Second message" latitude:0 longitude:1],
[RTGRouteNote noteWithMessage:@"Third message" latitude:1 longitude:0],
[RTGRouteNote noteWithMessage:@"Fourth message" latitude:0 longitude:0]];
[RTGRouteNote noteWithMessage:@"Fourth message" latitude:0 longitude:0]
];
GRPCStreamingProtoCall *call = [_service routeChatWithResponseHandler:self
callOptions:nil];
GRPCStreamingProtoCall *call = [_service routeChatWithResponseHandler:self callOptions:nil];
[call start];
for (RTGRouteNote *note in notes) {
[call writeMessage:note];
@ -322,8 +335,8 @@ static NSString * const kHostAddress = @"localhost:50051";
- (void)didReceiveProtoMessage:(GPBMessage *)message {
RTGRouteNote *note = (RTGRouteNote *)message;
if (note) {
NSString *str =[NSString stringWithFormat:@"%@\nGot message %@ at %@",
self.outputLabel.text, note.message, note.location];
NSString *str = [NSString stringWithFormat:@"%@\nGot message %@ at %@", self.outputLabel.text,
note.message, note.location];
self.outputLabel.text = str;
NSLog(@"Got message %@ at %@", note.message, note.location);
}

Loading…
Cancel
Save