Skip to content

Commit

Permalink
[Style] reorganize combine logic from SHFirestoreHelpers.swift to Com…
Browse files Browse the repository at this point in the history
…bine+Helpers
  • Loading branch information
SHcommit committed May 8, 2024
1 parent ca1de5b commit d1b6834
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Sources/SHFirestoreService/Combine+FutureHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import Foundation
#if canImport(Combine) && os(iOS) && swift(>=5.0)
import Combine

@available(swift 5.0)
@available(iOS 13.0, *)

public extension Publisher
where Output == Void, Failure == FirestoreServiceError {
func sink(promise: @escaping Future<Output, Error>.Promise) -> AnyCancellable {
Expand Down
13 changes: 13 additions & 0 deletions Sources/SHFirestoreService/Combine+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ import Foundation
#if canImport(Combine) && os(iOS) && swift(>=5.0)
import Combine

@available(swift 5.0)
@available(iOS 13.0, *)

internal extension Publisher {
func subscribeAndReceive(
on queue: DispatchQueue
) -> Publishers.ReceiveOn<Publishers.SubscribeOn<Self, DispatchQueue>, DispatchQueue> {
return self.subscribe(on: queue).receive(on: queue)
}
}

internal extension Publisher where Failure == Error {
func convertFirestoreServiceError(
) -> Publishers.MapError<Self, FirestoreServiceError> {
return self.mapError { error in
FirestoreServiceError.wrappedfirestoreError(error)
}
}
}

#endif
19 changes: 8 additions & 11 deletions Sources/SHFirestoreService/SHFirestoreHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
// Created by 양승현 on 4/24/24.
//

#if os(iOS) && swift(>=5.0)
import Foundation
import Combine

internal extension Publisher where Failure == Error {
func convertFirestoreServiceError(
) -> Publishers.MapError<Self, FirestoreServiceError> {
return self.mapError { error in
FirestoreServiceError.wrappedfirestoreError(error)
}
}
}
@available(swift 5.0)
@available(iOS 13.0, *)

internal extension Encodable {
func toDictionary() throws -> [String: Any] {
typealias Dictionary = [String: Any]
func toDictionary() throws -> Dictionary {
let data = try JSONEncoder().encode(self)
guard let dict = try JSONSerialization.jsonObject(with: data) as? [String: Any] else {
guard let dict = try JSONSerialization.jsonObject(with: data) as? Dictionary else {
throw Swift.EncodingError.invalidValue(
self,
Swift.EncodingError.Context.init(
Expand All @@ -30,3 +25,5 @@ internal extension Encodable {
return dict
}
}

#endif

0 comments on commit d1b6834

Please sign in to comment.