Adds class factory method to generated ProtoService classes

pull/3485/head
Nate Kibler 9 years ago
parent d09a28e4a3
commit 6d19724a90
  1. 5
      src/compiler/objective_c_generator.cc

@ -203,6 +203,7 @@ void PrintMethodImplementations(Printer *printer,
printer.Print( printer.Print(
"- (instancetype)initWithHost:(NSString *)host" "- (instancetype)initWithHost:(NSString *)host"
" NS_DESIGNATED_INITIALIZER;\n"); " NS_DESIGNATED_INITIALIZER;\n");
printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n");
printer.Print("@end\n"); printer.Print("@end\n");
} }
return output; return output;
@ -239,6 +240,10 @@ void PrintMethodImplementations(Printer *printer,
printer.Print(" packageName:(NSString *)packageName\n"); printer.Print(" packageName:(NSString *)packageName\n");
printer.Print(" serviceName:(NSString *)serviceName {\n"); printer.Print(" serviceName:(NSString *)serviceName {\n");
printer.Print(" return [self initWithHost:host];\n"); printer.Print(" return [self initWithHost:host];\n");
printer.Print("}\n\n");
printer.Print("// Class factory method\n");
printer.Print("+ (instancetype)serviceWithHost:(NSString *)host {\n");
printer.Print(" return [[self alloc] initWithHost:host];\n");
printer.Print("}\n\n\n"); printer.Print("}\n\n\n");
for (int i = 0; i < service->method_count(); i++) { for (int i = 0; i < service->method_count(); i++) {

Loading…
Cancel
Save