Skip to content

Commit

Permalink
Fix a header search path for CgRPC and some compile error for „Echo“ …
Browse files Browse the repository at this point in the history
…example
  • Loading branch information
koichi.tanaka committed Jul 21, 2018
1 parent 0c3ce55 commit 44dfc81
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Examples/EchoXcode/Echo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = EQHXZ8M8AV;
HEADER_SEARCH_PATHS = ../../Sources/CgRPC/include;
INFOPLIST_FILE = Echo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.google.Echo;
Expand All @@ -494,6 +495,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = EQHXZ8M8AV;
HEADER_SEARCH_PATHS = ../../Sources/CgRPC/include;
INFOPLIST_FILE = Echo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.google.Echo;
Expand Down
1 change: 1 addition & 0 deletions Examples/EchoXcode/Echo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import Cocoa
import SwiftGRPC

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
Expand Down
57 changes: 29 additions & 28 deletions Examples/EchoXcode/Echo/EchoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
let certificateURL = Bundle.main.url(forResource: "ssl",
withExtension: "crt")!
let certificates = try! String(contentsOf: certificateURL)
service = Echo_EchoServiceClient(address: address, certificates: certificates, host: host)
let arguments: [Channel.Argument] = [.sslTargetNameOverride(host)]
service = Echo_EchoServiceClient(address: address, certificates: certificates, arguments: arguments)
}
if let service = service {
service.host = "example.com" // sample override
service.metadata = Metadata([
service.metadata = try! Metadata([
"x-goog-api-key": "YOUR_API_KEY",
"x-ios-bundle-identifier": Bundle.main.bundleIdentifier!
])
Expand Down Expand Up @@ -197,17 +198,13 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
guard let expandCall = expandCall else {
return
}
try expandCall.receive { response, error in
if let responseMessage = response {
self.displayMessageReceived(responseMessage.text)

try expandCall.receive { (response) in
if case let result?? = response.result {
self.displayMessageReceived(result.text)
try! self.receiveExpandMessages()
} else if let error = error {
switch error {
case .endOfStream:
self.displayMessageReceived("Done.")
default:
self.displayMessageReceived("No message received. \(error)")
}
} else if let error = response.error {
self.displayMessageReceived("No message received. \(error)")
}
}
}
Expand All @@ -217,7 +214,11 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
var requestMessage = Echo_EchoRequest()
requestMessage.text = messageField.stringValue
displayMessageSent(requestMessage.text)
try collectCall.send(requestMessage) { error in print(error) }
try collectCall.send(requestMessage) { (error) in
if let error = error {
print(error)
}
}
}
}

Expand All @@ -226,25 +227,25 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
var requestMessage = Echo_EchoRequest()
requestMessage.text = messageField.stringValue
displayMessageSent(requestMessage.text)
try updateCall.send(requestMessage) { error in print(error) }
try updateCall.send(requestMessage) { (error) in
if let error = error {
print(error)
}
}
}
}

func receiveUpdateMessages() throws {
guard let updateCall = updateCall else {
return
}
try updateCall.receive { response, error in
if let responseMessage = response {
self.displayMessageReceived(responseMessage.text)

try updateCall.receive { (response) in
if case let result?? = response.result {
self.displayMessageReceived(result.text)
try! self.receiveUpdateMessages()
} else if let error = error {
switch error {
case .endOfStream:
self.displayMessageReceived("Done.")
default:
self.displayMessageReceived("No message received. \(error)")
}
} else if let error = response.error {
self.displayMessageReceived("No message received. \(error)")
}
}
}
Expand All @@ -261,10 +262,10 @@ class EchoViewController: NSViewController, NSTextFieldDelegate {
}
if let collectCall = collectCall {
do {
try collectCall.closeAndReceive { response, error in
if let response = response {
self.displayMessageReceived(response.text)
} else if let error = error {
try collectCall.closeAndReceive { (response) in
if let result = response.result {
self.displayMessageReceived(result.text)
} else if let error = response.error {
self.displayMessageReceived("No message received. \(error)")
}
self.collectCall = nil
Expand Down

0 comments on commit 44dfc81

Please sign in to comment.