|
| 1 | +--- |
| 2 | +layout: docs |
| 3 | +title: Objective-C Quick Start |
| 4 | +--- |
| 5 | + |
| 6 | +<h1 class="page-header">gRPC in 3 minutes (Objective-C)</h1> |
| 7 | + |
| 8 | +This document shows you how to install and build an Objective-C client for a simple Hello World example, as used in the [Overview](/docs/index.shtml). |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well as the relevant tools to generate the client library code (and a server in another language, for testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc). |
| 13 | + |
| 14 | +## Hello Objective-C gRPC! |
| 15 | + |
| 16 | +Here's how to build and run the Objective-C implementation of the [Hello World](https://github.com/grpc/grpc-common/blob/master/protos/helloworld.proto) example used in the [Overview](/docs/index.html). |
| 17 | + |
| 18 | +The example code for this and our other examples lives in the `grpc-common` |
| 19 | +GitHub repository. Clone this repository to your local machine by running the |
| 20 | +following command: |
| 21 | + |
| 22 | + |
| 23 | +```` |
| 24 | +$ git clone https://github.com/grpc/grpc-common.git |
| 25 | +``` |
| 26 | +
|
| 27 | +Change your current directory to `grpc-common/objective-c/helloworld` |
| 28 | +
|
| 29 | +```` |
| 30 | +$ cd grpc-common/objective-c/helloworld |
| 31 | +``` |
| 32 | +
|
| 33 | +### Try it! |
| 34 | +To try the sample app, we need a gRPC server running locally. Let's compile and run, for example, the C++ `Greeter` server: |
| 35 | +
|
| 36 | +``` |
| 37 | +$ pushd ../../cpp/helloworld |
| 38 | +$ make |
| 39 | +$ ./greeter_server & |
| 40 | +$ popd |
| 41 | +``` |
| 42 | +
|
| 43 | +Now have Cocoapods generate and install the client library for our .proto files: |
| 44 | +
|
| 45 | +``` |
| 46 | +$ pod install |
| 47 | +``` |
| 48 | +
|
| 49 | +This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet on your computer's cache). |
| 50 | +
|
| 51 | +Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling code in `main.m` and see the results in XCode's log console. |
| 52 | +
|
| 53 | +The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server responds with a `HLWHelloResponse`, which contains a string that is then output to the log. |
| 54 | +
|
| 55 | +## Tutorial |
| 56 | +
|
| 57 | +You can find a more detailed tutorial in [gRPC Basics: Objective-C](/docs/tutorials/basic/objective-c.html). |
0 commit comments