From 381f9269233dda2ca78cf62e13c6064654712f00 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Tue, 23 Jan 2024 08:54:27 -0800 Subject: [PATCH] `RevenueCatUI`: fix CocoaPods build (#3594) Fixes https://circleci.com/gh/RevenueCat/purchases-ios/163464 Unfortunately CocoaPods does not support symlinks, and neither `pod spec lint` nor our installation tests (because they use a local reference) can catch that. This replaces it with a copy of the file. --- .../Helpers/Optional+Extensions.swift | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) mode change 120000 => 100644 RevenueCatUI/Helpers/Optional+Extensions.swift diff --git a/RevenueCatUI/Helpers/Optional+Extensions.swift b/RevenueCatUI/Helpers/Optional+Extensions.swift deleted file mode 120000 index 0ef4b812b0..0000000000 --- a/RevenueCatUI/Helpers/Optional+Extensions.swift +++ /dev/null @@ -1 +0,0 @@ -../../Sources/FoundationExtensions/Optional+Extensions.swift \ No newline at end of file diff --git a/RevenueCatUI/Helpers/Optional+Extensions.swift b/RevenueCatUI/Helpers/Optional+Extensions.swift new file mode 100644 index 0000000000..f93e64598b --- /dev/null +++ b/RevenueCatUI/Helpers/Optional+Extensions.swift @@ -0,0 +1,46 @@ +// +// 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 +// +// Optional+Extensions.swift +// +// Created by Nacho Soto on 3/30/22. + +import Foundation + +/// Protocol definition to be able to use `Optional` as a type. +internal protocol OptionalType { + + associatedtype Wrapped + + init(optional: Wrapped?) + var asOptional: Wrapped? { get } + +} + +extension Optional: OptionalType { + + init(optional: Wrapped?) { self = optional } + + var asOptional: Wrapped? { return self } + +} + +extension OptionalType { + + /// - Returns: unwrapped value if present. + /// - Throws: `error` if the value is not present. + func orThrow(_ error: @autoclosure () -> Error) throws -> Wrapped { + if let value = self.asOptional { + return value + } else { + throw error() + } + } + +}