Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
This repository contains a gRPC Swift API and code generator.
It is intended for use with Apple's SwiftProtobuf support for
Protocol Buffers. Both projects contain code generation plugins for
Google's Protocol Buffer compiler, and both contain libraries of supporting code
that is needed to build and run the generated code.
APIs and generated code is provided for both gRPC clients and servers, and can be built either with Xcode or the Swift Package Manager. Support is provided for all four gRPC API styles (Unary, Server Streaming, Client Streaming, and Bidirectional Streaming) and connections can be made either over secure (TLS) or insecure channels.
||gRPC-Swift||Actively developed and supported|
|0.x||gRPC C library||
||SwiftGRPC||No longer developed; security fixes only|
The remainder of this README refers to the 1.x version of gRPC Swift.
gRPC Swift's platform support is identical to the platform support of Swift NIO.
Note that gRPC Swift uses NIO 2 and requires Swift to be version 5.2 or higher.
Getting gRPC Swift
There are two parts to gRPC Swift: the gRPC library and an API code generator.
Getting the gRPC library
Swift Package Manager
The Swift Package Manager is the preferred way to get gRPC Swift. Simply add the
package dependency to your
dependencies: [ .package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0-alpha.23") ]
...and depend on
"GRPC" in the necessary targets:
.target( name: ..., dependencies: [.product(name: "GRPC", package: "grpc-swift")] ]
From Xcode 11 it is possible to add Swift Package dependencies to Xcode
projects and link targets to products of those packages; this is the
easiest way to integrate gRPC Swift with an existing
Alternatively, gRPC Swift can be manually integrated into a project:
- Build an Xcode project:
swift package generate-xcodeproj,
- Add the generated project to your own project, and
- Add a build dependency on
gRPC Swift is currently available from CocoaPods. To integrate, add
the following line to your
pod 'gRPC-Swift', '~> 1.0.0-alpha.23'
pod install from command line and use your project's generated
.xcworkspace file. You might also need to add
use_frameworks! to your
Binary releases of
protoc, the Protocol Buffer Compiler, are available on
To build the plugins, run
make plugins in the main directory. This uses the
Swift Package Manager to build both of the necessary plugins:
protoc-gen-swift, which generates Protocol Buffer support code and
protoc-gen-grpc-swift, which generates gRPC interface code.
To install these plugins, just copy the two executables (
protoc-gen-grpc-swift) that show up in the main directory into a directory
that is part of your
PATH environment variable. Alternatively the full path to
the plugins can be specified when using
Alternatively, you can get the latest precompiled version of the plugins by adding
the following line to your
The plugins are available in the
Pods/gRPC-Swift-Plugins/ folder afterwards.
gRPC Swift has a number of tutorials and examples available. They are split across two directories:
/Sources/Examplescontains examples which do not require additional dependencies and may be built using the Swift Package Manager.
/Examplescontains examples which rely on external dependencies or may not be built by the Swift Package Manager (such as an iOS app).
Some of the examples are accompanied by tutorials, including:
- A quick start guide for creating and running your first gRPC service.
- A basic tutorial covering the creation and implementation of a gRPC service using all four call types as well as the code required to setup and run a server and make calls to it using a generated client.
- An interceptors tutorial covering how to create and use interceptors with gRPC Swift.
docs directory contains documentation, including:
- Options for the
- How to configure TLS in
- How to configure keepalive in
- Support for Apple Platforms and NIO Transport Services in
Please get involved! See our guidelines for contributing.
|Last commit: 4 hours ago|
You may find interesting
gRPC Swift 1.0.0-alpha.23 - 2021-01-22T13:32:58
This release includes two noteworthy changes that users should be aware of:
- The minimum supported version of Swift has been raised to 5.2.
- The interface between gRPC and the generated server code has changed. The old interface has been deprecated and will be removed in an upcoming release. Users are required to re-generate their server code, no other action is necessary.
- Raise the minimum Swift version to 5.2 (#1106)
- Add client API for providing a custom SSL certificate verification callback (#1107, patch credit to @franck-clement-ug)
- Expose the remote address on the server interceptor context (#1081)
- Refactor how gRPC handles incoming RPCs on the server. Note that this change impacts how the generated server code and gRPC interact; users must therefore re-generate their server code. (#1093, #1095, #1097, #1098, #1100, #1101, #1110, #1105, #1102)
- Added support of the protobuf optional feature (#1084, patch credit to @azatZul)
- Compact the client 'ChannelPipeline' to reduce runtime costs (#1083)
- Avoid unnecessary (and expensive) copies of client and server interceptor contexts (#1090, #1091, #1092)
- Update Cocoapods (#1082)
- Add a script for diffing cachegrind output (#1086)
- Add a handful more perf tests. (#1096)