blob: 75df1a7a26e95fa70c8b50894e4ee53857c7c778 [file] [log] [blame] [view]
murgatroid995de22f52015-06-12 11:21:55 -07001#gRPC in 3 minutes (Objective-C)
murgatroid99042b9122015-06-11 14:23:32 -07002
3## Installation
4
Jorge Canizales54f4d532015-07-17 17:53:06 -07005To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well
6as the relevant tools to generate the client library code (and a server in another language, for
7testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc).
murgatroid99042b9122015-06-11 14:23:32 -07008
murgatroid995de22f52015-06-12 11:21:55 -07009## Hello Objective-C gRPC!
murgatroid99042b9122015-06-11 14:23:32 -070010
Stanley Cheung56debcb2015-08-31 12:17:34 -070011Here's how to build and run the Objective-C implementation of the [Hello World](../../protos/helloworld.proto)
Stanley Cheung0a268212015-08-27 14:38:38 -070012example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples).
murgatroid99042b9122015-06-11 14:23:32 -070013
Stanley Cheung0a268212015-08-27 14:38:38 -070014The example code for this and our other examples lives in the `examples` directory. Clone
Jorge Canizales54f4d532015-07-17 17:53:06 -070015this repository to your local machine by running the following command:
murgatroid99042b9122015-06-11 14:23:32 -070016
17
18```sh
Stanley Cheung0a268212015-08-27 14:38:38 -070019$ git clone https://github.com/grpc/grpc.git
murgatroid99042b9122015-06-11 14:23:32 -070020```
21
Stanley Cheung0a268212015-08-27 14:38:38 -070022Change your current directory to `examples/objective-c/helloworld`
murgatroid99042b9122015-06-11 14:23:32 -070023
24```sh
Stanley Cheung0a268212015-08-27 14:38:38 -070025$ cd examples/objective-c/helloworld
murgatroid99042b9122015-06-11 14:23:32 -070026```
27
28### Try it!
Jorge Canizales54f4d532015-07-17 17:53:06 -070029To try the sample app, we need a gRPC server running locally. Let's compile and run, for example,
30the C++ server in this repository:
murgatroid99042b9122015-06-11 14:23:32 -070031
32```shell
33$ pushd ../../cpp/helloworld
34$ make
35$ ./greeter_server &
36$ popd
37```
38
39Now have Cocoapods generate and install the client library for our .proto files:
40
41```shell
42$ pod install
43```
44
Jorge Canizales54f4d532015-07-17 17:53:06 -070045(This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet
46on your computer's cache.)
murgatroid99042b9122015-06-11 14:23:32 -070047
Jorge Canizales54f4d532015-07-17 17:53:06 -070048Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling
49code in `main.m` and see the results in XCode's log console.
murgatroid99042b9122015-06-11 14:23:32 -070050
Jorge Canizales54f4d532015-07-17 17:53:06 -070051The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server
52responds with a `HLWHelloResponse`, which contains a string that is then output to the log.
murgatroid995de22f52015-06-12 11:21:55 -070053
murgatroid99042b9122015-06-11 14:23:32 -070054## Tutorial
55
Stanley Cheung56debcb2015-08-31 12:17:34 -070056You can find a more detailed tutorial in [gRPC Basics: Objective-C](../route_guide/README.md).