Files
Rick 62902da52c fix(remote-config): align edge-case handling with Android implementation (#7173)
* Prefetch item-level remote config blobs

* Match workflow duplicate offering behavior

* Require complete remote UI config

* Update workflow UI config test fixtures

* refactor(remote-config): treat prefetch refs as unordered

* fix(remote-config): preserve prefetch blob order

* chore(remote-config): clean up UI config review notes

* fix(remote-config): default UI custom variables in decoder

* fix(remote-config): ignore embedded workflow UI config

* test(remote-config): update UI config fixtures

* refactor(remote-config): pass workflow ui config separately

* test(remote-config): wait for inline blob write attempt

* fix(remote-config): surface unavailable workflow ui config
2026-07-10 10:40:49 +02:00

64 lines
1.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
//
// Array+Extensions.swift
//
// Created by Nacho Soto on 2/17/22.
import Foundation
extension Array {
/// Equivalent to `removeFirst()` but it returns `Optional` if the collection is empty.
mutating func popFirst() -> Element? {
guard !self.isEmpty else { return nil }
return self.removeFirst()
}
}
extension Collection {
/// - Returns: an element if and only if it's the only one in the collection
var onlyElement: Element? {
guard self.count == 1, let first = self.first else {
return nil
}
return first
}
/// Returns the element at the specified index if it exists, otherwise nil.
subscript(safe index: Index) -> Element? {
return self.indices.contains(index) ? self[index] : nil
}
}
extension Sequence where Element: AdditiveArithmetic {
/// - Returns: the sum of the elements in the sequence.
func sum() -> Element {
return reduce(.zero, +)
}
}
extension Sequence where Element: Hashable {
/// Returns the sequence's unique elements, preserving each element's first occurrence.
func deduplicated() -> [Element] {
var seen: Set<Element> = []
return self.filter { seen.insert($0).inserted }
}
}