Files
purchases-ios/Sources/Networking/Operations/PostSubscriberAttributesOperation.swift
Mark Villacampa 6f8e53ac40 Fix Xcode 16 warnings (#4334)
When compiling with Xcode 16, we started throwing a bunch of new warnings. Here's a list and explanation of each:

- The most common one was needing to explicitly restate the @unchecked Sendable conformance from a parent class.
- There were a couple switches where a new entry was added in tvOS but only for iOS 18, and needed to add it to make it exhaustive.
- There we a couple of places where we were adding a protocol conformance to a class from a different module e.g. extension DispatchTimeInterval: Comparable. This is considered unsafe now because the owners of the module could add the conformance later. Solved by removing the conformance which wasn't being used widely in the codebase, only in tests.
- Finally there was a class where we were capturing SKRequest and SKProductsRequest instances in a sendable block, but only to either log something, or use them as dictionary key, so I just made the classes Sendable (with the new @retroactice attribute because they belong to a different module)
2024-10-02 11:53:45 +02:00

85 lines
2.5 KiB
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// PostSubscriberAttributesOperation.swift
//
// Created by Joshua Liebowitz on 11/18/21.
import Foundation
class PostSubscriberAttributesOperation: NetworkOperation {
private let configuration: UserSpecificConfiguration
private let subscriberAttributes: SubscriberAttribute.Dictionary
private let responseHandler: CustomerAPI.SimpleResponseHandler?
init(configuration: UserSpecificConfiguration,
subscriberAttributes: SubscriberAttribute.Dictionary,
completion: CustomerAPI.SimpleResponseHandler?) {
self.configuration = configuration
self.subscriberAttributes = subscriberAttributes
self.responseHandler = completion
super.init(configuration: configuration)
}
override func begin(completion: @escaping () -> Void) {
post(completion: completion)
}
private func post(completion: @escaping () -> Void) {
guard self.subscriberAttributes.count > 0 else {
Logger.warn(Strings.attribution.empty_subscriber_attributes)
self.responseHandler?(.emptySubscriberAttributes())
return
}
let appUserID = self.configuration.appUserID
guard appUserID.isNotEmpty else {
self.responseHandler?(.missingAppUserID())
completion()
return
}
let request = HTTPRequest(method: .post(Body(self.subscriberAttributes)),
path: .postSubscriberAttributes(appUserID: appUserID))
self.httpClient.perform(request) { (response: VerifiedHTTPResponse<HTTPEmptyResponseBody>.Result) in
defer {
completion()
}
self.responseHandler?(response.error.map(BackendError.networkError))
}
}
}
// Restating inherited @unchecked Sendable from Foundation's Operation
extension PostSubscriberAttributesOperation: @unchecked Sendable {}
private extension PostSubscriberAttributesOperation {
struct Body: HTTPRequestBody {
let attributes: AnyEncodable
init(_ attributes: SubscriberAttribute.Dictionary) {
self.attributes = AnyEncodable(
SubscriberAttribute.map(subscriberAttributes: attributes)
)
}
}
}