Skip to content

Commit

Permalink
Fixes for JSONCodable in PubNubObjc+Publish.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jguz-pubnub committed Aug 26, 2024
1 parent 19b7e20 commit 7f5d8f2
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions Sources/PubNub/KMM/PubNubObjC+Publish.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ import Foundation

// MARK: - Publish

extension PubNubObjC {
private func asOptionalCodable(_ object: Any?) -> JSONCodable? {
if let object {
return asCodable(object)
} else {
return nil
}
}

private func asCodable(_ object: Any) -> JSONCodable {
if let codableValue = object as? JSONCodable {
return codableValue
} else {
return AnyJSON(object)
}
}
}

@objc
public extension PubNubObjC {
func publish(
Expand All @@ -23,17 +41,12 @@ public extension PubNubObjC {
onSuccess: @escaping ((Timetoken) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
let metadata: AnyJSON? = if let meta = meta {
AnyJSON(meta)
} else {
nil
}
pubnub.publish(
channel: channel,
message: AnyJSON(message),
message: asCodable(message),
shouldStore: shouldStore?.boolValue,
storeTTL: shouldStore?.intValue,
meta: metadata
meta: asOptionalCodable(meta)
) {
switch $0 {
case .success(let timetoken):
Expand All @@ -55,7 +68,7 @@ public extension PubNubObjC {
onSuccess: @escaping ((Timetoken) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.signal(channel: channel, message: AnyJSON(message)) {
pubnub.signal(channel: channel, message: asCodable(message)) {
switch $0 {
case .success(let timetoken):
onSuccess(timetoken)
Expand Down

0 comments on commit 7f5d8f2

Please sign in to comment.