Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ only_rules:
- force_unwrapping
- force_try
- force_cast
- custom_rules

included:
- REES46/Classes/Core
Expand Down Expand Up @@ -33,3 +34,16 @@ excluded:
force_unwrapping: error
force_try: error
force_cast: error

custom_rules:
# A synchronized copy of the SDK renames the module and the `Rees46` facade to the same word, so
# `REES46.X` there means the facade's nested type, not the module's: the copy stops compiling.
module_qualified_name:
name: "Module-qualified name"
regex: '\bREES46\.[A-Z]'
excluded_match_kinds:
- comment
- doccomment
- string
message: "A synchronized copy renames the module and Rees46 to the same word: use a plain name or LegacySdkError / LegacyPushEvent"
severity: error
14 changes: 14 additions & 0 deletions REES46/Classes/Sdk/Facade/LegacyTypes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

/**
The SDK's first error type, under a name of its own.

`Rees46` nests a `SdkError` of its own, so inside it a plain `SdkError` is the nested one. The
module's name cannot point at this one either: a synchronized copy of the SDK renames the module
and `Rees46` to the same word, where the module-qualified name would mean the nested type. This
name stays the same in every copy.
*/
public typealias LegacySdkError = SdkError

/// The push events of earlier versions, under a name of its own for the same reason as `LegacySdkError`.
public typealias LegacyPushEvent = PushEvent
8 changes: 4 additions & 4 deletions REES46/Classes/Sdk/Facade/Rees46+Bridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ extension Rees46 {
/// otherwise one made from `legacy` — `network` offline, `decoding` for an answer the SDK could
/// not take, `notInitialized`, `shopBlocked` for a refused shop, `invalidArgument` with the
/// message of another `.custom`, `timeout` otherwise.
public static func error(of legacy: REES46.SdkError) -> Rees46.SdkError {
public static func error(of legacy: LegacySdkError) -> Rees46.SdkError {
currentError() ?? SimplePersonalizationSDK.newCoreError(legacy)
}

/// A completion for any old method that reports the whole result to `onResult`, once, on the
/// thread the SDK answers on.
public static func completion<T>(_ onResult: @escaping (Result<T, Rees46.SdkError>) -> Void) -> (Result<T, REES46.SdkError>) -> Void {
public static func completion<T>(_ onResult: @escaping (Result<T, Rees46.SdkError>) -> Void) -> (Result<T, LegacySdkError>) -> Void {
{ result in
onResult(result.mapError { error(of: $0) })
}
}

/// A completion for an old method that reports only an error — `Rees46.initialize` — that hands
/// `onError` the whole error, or `nil` for none, once, on the thread the SDK answers on.
public static func completion(_ onError: @escaping (Rees46.SdkError?) -> Void) -> (REES46.SdkError?) -> Void {
public static func completion(_ onError: @escaping (Rees46.SdkError?) -> Void) -> (LegacySdkError?) -> Void {
{ legacy in
onError(legacy.map { error(of: $0) })
}
Expand Down Expand Up @@ -118,7 +118,7 @@ extension PersonalizationSDK {
device id, as it always has; on `Rees46Config.coreV2` it, too, hears the answer once it went.
*/
public func setPushToken(_ token: Rees46.PushToken, completion: @escaping (Result<Void, Rees46.SdkError>) -> Void) {
let finish: (Result<Void, REES46.SdkError>) -> Void = { result in
let finish: (Result<Void, LegacySdkError>) -> Void = { result in
let mapped = result.mapError { Rees46.BridgeErrors.error(of: $0) }
DispatchQueue.main.async { completion(mapped) }
}
Expand Down
6 changes: 3 additions & 3 deletions REES46/Classes/Sdk/Facade/Rees46.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public enum Rees46 {
@discardableResult
public static func initialize(
_ config: Rees46Config,
completion: ((REES46.SdkError?) -> Void)? = nil
completion: ((LegacySdkError?) -> Void)? = nil
) -> PersonalizationSDK {
withCreationLock {
lock.lock()
Expand Down Expand Up @@ -125,7 +125,7 @@ public enum Rees46 {
private static func joinExisting(
_ existing: PersonalizationSDK,
config: Rees46Config,
completion: ((REES46.SdkError?) -> Void)?
completion: ((LegacySdkError?) -> Void)?
) -> () -> Void {
guard let instance = existing as? SimplePersonalizationSDK else {
// Another conformer the app registered: it has no outcome to tell.
Expand Down Expand Up @@ -349,7 +349,7 @@ public enum Rees46 {
`track/received` as before.
*/
@_disfavoredOverload
public static func handlePush(_ payload: [AnyHashable: Any], event: REES46.PushEvent) {
public static func handlePush(_ payload: [AnyHashable: Any], event: LegacyPushEvent) {
route(payload, PushRoute(event))
}

Expand Down
Loading