Last active
December 11, 2020 20:24
-
-
Save ericlewis/0fc8a5d2e10d2014fba0854ced2fbf24 to your computer and use it in GitHub Desktop.
Simple future publishers for SKCloudServiceController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // StoreKit+Combine.swift | |
| // | |
| // Created by Eric Lewis on 12/11/20. | |
| // | |
| import StoreKit | |
| import Combine | |
| extension SKCloudServiceController { | |
| func requestUserTokenPublisher(for developerToken: String) -> Future<String, Error> { | |
| Future { finished in | |
| self.requestUserToken(forDeveloperToken: developerToken) { | |
| if let token = $0 { | |
| finished(.success(token)) | |
| } else if let error = $1 { | |
| finished(.failure(error)) | |
| } | |
| } | |
| } | |
| } | |
| func requestCapabilitiesPublisher() -> Future<SKCloudServiceCapability, Error> { | |
| Future { finished in | |
| self.requestCapabilities { | |
| guard let error = $1 else { | |
| finished(.success($0)) | |
| return | |
| } | |
| finished(.failure(error)) | |
| } | |
| } | |
| } | |
| func requestStorefrontIdentifierPublisher() -> Future<String, Error> { | |
| Future { finished in | |
| self.requestStorefrontIdentifier { | |
| if let storefrontIdentifier = $0 { | |
| finished(.success(storefrontIdentifier)) | |
| } else if let error = $1 { | |
| finished(.failure(error)) | |
| } | |
| } | |
| } | |
| } | |
| func requestStorefrontCountryCodePublisher() -> Future<String, Error> { | |
| Future { finished in | |
| self.requestStorefrontCountryCode { | |
| if let storefrontCountryCode = $0 { | |
| finished(.success(storefrontCountryCode)) | |
| } else if let error = $1 { | |
| finished(.failure(error)) | |
| } | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
probably not great but do let me know what to change / add. lazy!