Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 77473ea

Browse files
committed
fix(models): drop protocol defaults
1 parent aa251b0 commit 77473ea

File tree

6 files changed

+61
-15
lines changed

6 files changed

+61
-15
lines changed

Example/OpenIapExample/Models/IapCompat.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ extension PurchaseIOS {
3131
}
3232
}
3333

34-
@available(iOS 15.0, *)
35-
extension PurchaseIOS: Identifiable {}
36-
3734
@available(iOS 15.0, *)
3835
extension ProductIOS {
3936
var productIdentifier: String { id }

Example/OpenIapExample/Screens/AvailablePurchasesScreen.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ struct AvailablePurchasesScreen: View {
3434
.disabled(iapStore.status.loadings.restorePurchases)
3535
}
3636
}
37-
.sheet(item: $selectedPurchase) { purchase in
38-
PurchaseDetailSheet(purchase: purchase)
37+
.sheet(isPresented: Binding(
38+
get: { selectedPurchase != nil },
39+
set: { if !$0 { selectedPurchase = nil } }
40+
)) {
41+
if let purchase = selectedPurchase {
42+
PurchaseDetailSheet(purchase: purchase)
43+
}
3944
}
4045
.alert("Error", isPresented: $showError) {
4146
Button("OK") {}

Example/OpenIapExample/Screens/PurchaseFlowScreen.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ struct PurchaseFlowScreen: View {
5959
} message: {
6060
Text(errorMessage)
6161
}
62-
.sheet(item: $selectedPurchase) { purchase in
63-
PurchaseDetailSheet(purchase: purchase)
62+
.sheet(isPresented: Binding(
63+
get: { selectedPurchase != nil },
64+
set: { if !$0 { selectedPurchase = nil } }
65+
)) {
66+
if let purchase = selectedPurchase {
67+
PurchaseDetailSheet(purchase: purchase)
68+
}
6469
}
6570
}
6671

Example/OpenIapExample/Screens/SubscriptionFlowScreen.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ struct SubscriptionFlowScreen: View {
179179
}
180180
.disabled(iapStore.status.isLoading)
181181
)
182-
.sheet(item: $selectedPurchase) { purchase in
183-
PurchaseDetailSheet(purchase: purchase)
182+
.sheet(isPresented: Binding(
183+
get: { selectedPurchase != nil },
184+
set: { if !$0 { selectedPurchase = nil } }
185+
)) {
186+
if let purchase = selectedPurchase {
187+
PurchaseDetailSheet(purchase: purchase)
188+
}
184189
}
185190
.alert("Error", isPresented: $showError) {
186191
Button("OK") {}

Sources/Models/Types.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,11 @@ public protocol MutationResolver {
935935
/// Consume a purchase token so it can be repurchased
936936
func consumePurchaseAndroid(_ purchaseToken: String) async throws -> Bool
937937
/// Open the native subscription management surface
938-
func deepLinkToSubscriptions(_ options: DeepLinkOptions? = nil) async throws -> Void
938+
func deepLinkToSubscriptions(_ options: DeepLinkOptions?) async throws -> Void
939939
/// Close the platform billing connection
940940
func endConnection() async throws -> Bool
941941
/// Finish a transaction after validating receipts
942-
func finishTransaction(purchase: PurchaseInput, isConsumable: Bool? = nil) async throws -> Void
942+
func finishTransaction(purchase: PurchaseInput, isConsumable: Bool?) async throws -> Void
943943
/// Establish the platform billing connection
944944
func initConnection() async throws -> Bool
945945
/// Present the App Store code redemption sheet
@@ -965,11 +965,11 @@ public protocol QueryResolver {
965965
/// Retrieve products or subscriptions from the store
966966
func fetchProducts(_ params: ProductRequest) async throws -> FetchProductsResult
967967
/// Get active subscriptions (filters by subscriptionIds when provided)
968-
func getActiveSubscriptions(_ subscriptionIds: [String]? = nil) async throws -> [ActiveSubscription]
968+
func getActiveSubscriptions(_ subscriptionIds: [String]?) async throws -> [ActiveSubscription]
969969
/// Fetch the current app transaction (iOS 16+)
970970
func getAppTransactionIOS() async throws -> AppTransaction?
971971
/// Get all available purchases for the current user
972-
func getAvailablePurchases(_ options: PurchaseOptions? = nil) async throws -> [Purchase]
972+
func getAvailablePurchases(_ options: PurchaseOptions?) async throws -> [Purchase]
973973
/// Retrieve all pending transactions in the StoreKit queue
974974
func getPendingTransactionsIOS() async throws -> [PurchaseIOS]
975975
/// Get the currently promoted product (iOS 11+)
@@ -981,7 +981,7 @@ public protocol QueryResolver {
981981
/// Get the transaction JWS (StoreKit 2)
982982
func getTransactionJwsIOS(_ sku: String) async throws -> String?
983983
/// Check whether the user has active subscriptions
984-
func hasActiveSubscriptions(_ subscriptionIds: [String]? = nil) async throws -> Bool
984+
func hasActiveSubscriptions(_ subscriptionIds: [String]?) async throws -> Bool
985985
/// Check introductory offer eligibility for a subscription group
986986
func isEligibleForIntroOfferIOS(_ groupID: String) async throws -> Bool
987987
/// Verify a StoreKit 2 transaction signature

scripts/generate-types.sh

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,40 @@ echo "Downloading Swift types for openiap-gql ${VERSION}..."
2222
curl -fL "${DOWNLOAD_URL}" -o "${TMP_DIR}/${ZIP_NAME}"
2323

2424
echo "Extracting ${SWIFT_FILE}..."
25-
unzip -p "${TMP_DIR}/${ZIP_NAME}" "${SWIFT_FILE}" > "${OUTPUT_PATH}"
25+
# Extract generated file
26+
TMP_SWIFT="${TMP_DIR}/${SWIFT_FILE}"
27+
unzip -p "${TMP_DIR}/${ZIP_NAME}" "${SWIFT_FILE}" > "${TMP_SWIFT}"
28+
export TMP_SWIFT OUTPUT_PATH
29+
30+
# Remove default arguments from protocol requirements (not supported in Swift)
31+
python3 - <<'PY'
32+
import os
33+
import re
34+
from pathlib import Path
35+
36+
source = Path(os.environ["TMP_SWIFT"])
37+
dest = Path(os.environ["OUTPUT_PATH"])
38+
39+
text = source.read_text()
40+
41+
defaults = {
42+
r"func deepLinkToSubscriptions\(_ options: DeepLinkOptions\? = nil\)":
43+
"func deepLinkToSubscriptions(_ options: DeepLinkOptions?)",
44+
r"func finishTransaction\(purchase: PurchaseInput, isConsumable: Bool\? = nil\)":
45+
"func finishTransaction(purchase: PurchaseInput, isConsumable: Bool?)",
46+
r"func getActiveSubscriptions\(_ subscriptionIds: \[String\]\? = nil\)":
47+
"func getActiveSubscriptions(_ subscriptionIds: [String]?)",
48+
r"func getAvailablePurchases\(_ options: PurchaseOptions\? = nil\)":
49+
"func getAvailablePurchases(_ options: PurchaseOptions?)",
50+
r"func hasActiveSubscriptions\(_ subscriptionIds: \[String\]\? = nil\)":
51+
"func hasActiveSubscriptions(_ subscriptionIds: [String]?)",
52+
}
53+
54+
for pattern, replacement in defaults.items():
55+
text = re.sub(pattern, replacement, text)
56+
57+
source.write_text(text)
58+
source.replace(dest)
59+
PY
2660

2761
echo "Wrote ${OUTPUT_PATH}"

0 commit comments

Comments
 (0)