Skip to content

Commit 258478f

Browse files
committed
Use optional binding when initializing a Channel with certificates.
1 parent 7ac0661 commit 258478f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/gRPC/Channel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public class Channel {
6767
/// - Parameter address: the address of the server to be called
6868
public init(address: String, certificates: String?, host: String?) {
6969
self.host = address
70-
if certificates == nil {
70+
if let certificates = certificates {
71+
underlyingChannel = cgrpc_channel_create_secure(address, certificates, host)
72+
} else {
7173
let bundle = Bundle(for: Channel.self)
7274
let url = bundle.url(forResource: "roots", withExtension: "pem")!
7375
let data = try! Data(contentsOf: url)
7476
let s = String(data: data, encoding: .ascii)
7577
underlyingChannel = cgrpc_channel_create_secure(address, s, host)
76-
} else {
77-
underlyingChannel = cgrpc_channel_create_secure(address, certificates, host)
7878
}
7979
completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_channel_completion_queue(underlyingChannel))
8080
completionQueue.name = "Client" // only for debugging

0 commit comments

Comments
 (0)