blob: 81c5aaa7bcb4e665433d41bc924ab20ce3d52558 [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 Canizales1f5d62b2015-10-27 10:50:03 -070015this repository to your local machine by running the following commands:
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
Jorge Canizales1f5d62b2015-10-27 10:50:03 -070020$ cd grpc
21$ git submodule update --init
murgatroid99042b9122015-06-11 14:23:32 -070022```
23
Stanley Cheung0a268212015-08-27 14:38:38 -070024Change your current directory to `examples/objective-c/helloworld`
murgatroid99042b9122015-06-11 14:23:32 -070025
26```sh
Stanley Cheung0a268212015-08-27 14:38:38 -070027$ cd examples/objective-c/helloworld
murgatroid99042b9122015-06-11 14:23:32 -070028```
29
30### Try it!
Jorge Canizales54f4d532015-07-17 17:53:06 -070031To try the sample app, we need a gRPC server running locally. Let's compile and run, for example,
32the C++ server in this repository:
murgatroid99042b9122015-06-11 14:23:32 -070033
34```shell
35$ pushd ../../cpp/helloworld
36$ make
37$ ./greeter_server &
38$ popd
39```
40
41Now have Cocoapods generate and install the client library for our .proto files:
42
43```shell
44$ pod install
45```
46
Jorge Canizales54f4d532015-07-17 17:53:06 -070047(This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet
48on your computer's cache.)
murgatroid99042b9122015-06-11 14:23:32 -070049
Jorge Canizales54f4d532015-07-17 17:53:06 -070050Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling
51code in `main.m` and see the results in XCode's log console.
murgatroid99042b9122015-06-11 14:23:32 -070052
Jorge Canizales54f4d532015-07-17 17:53:06 -070053The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server
54responds with a `HLWHelloResponse`, which contains a string that is then output to the log.
murgatroid995de22f52015-06-12 11:21:55 -070055
murgatroid99042b9122015-06-11 14:23:32 -070056## Tutorial
57
Jorge Canizales1f5d62b2015-10-27 10:50:03 -070058You can find a more detailed tutorial in [gRPC Basics: Objective-C](http://www.grpc.io/docs/tutorials/basic/objective-c.html).