Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cast matches in case statements #51

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions Examples/topics/Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import momento

func main() async {
print("Running Momento Topics example!")
let cacheName = "my-cache"
let topicName = "my-topic"
let cacheName = "my-cache"
let topicName = "my-topic"

var creds: CredentialProviderProtocol
do {
Expand All @@ -18,8 +18,8 @@ func main() async {
let subscribeResponse = await client.subscribe(cacheName: cacheName, topicName: topicName)

switch subscribeResponse {
case is TopicSubscribeError:
print("Subscribe error: \((subscribeResponse as! TopicSubscribeError).description)")
case let subscribeError as TopicSubscribeError:
print("Subscribe error: \(subscribeError.description)")
return
case is TopicSubscribeSuccess:
print("Successful subscription!")
Expand All @@ -34,12 +34,11 @@ func main() async {
for try await item in subscription {
var value: String = ""
switch item {
case is TopicSubscriptionItemText:
value = (item as! TopicSubscriptionItemText).value
case let textItem as TopicSubscriptionItemText:
value = textItem.value
print("Subscriber recieved text message: \(value)")
case is TopicSubscriptionItemBinary:
let binaryValue = (item as! TopicSubscriptionItemBinary).value
value = String(decoding: binaryValue, as: UTF8.self)
case let binaryItem as TopicSubscriptionItemBinary:
value = String(decoding: binaryItem.value, as: UTF8.self)
print("Subscriber recieved binary message: \(value)")
default:
print("received unknown item type: \(item)")
Expand All @@ -63,8 +62,8 @@ func main() async {

// Check the response type (error or success?)
switch publishResponse {
case is TopicPublishError:
print("Publish error: \((publishResponse as! TopicPublishError).description)")
case let publishError as TopicPublishError:
print("Publish error: \(publishError.description)")
return
case is TopicPublishSuccess:
print("Successfully published: \(message)")
Expand Down
Loading