fix: Use two-parameter API for Capacitor 8 Swift compatibility#158
Open
sgalloway wants to merge 1 commit intocapacitor-community:masterfrom
Open
fix: Use two-parameter API for Capacitor 8 Swift compatibility#158sgalloway wants to merge 1 commit intocapacitor-community:masterfrom
sgalloway wants to merge 1 commit intocapacitor-community:masterfrom
Conversation
The Capacitor 8 xcframework requires the two-parameter style for
CAPPluginCall accessor methods:
- call.getString("key", "default") instead of call.getString("key") ?? "default"
- call.getFloat("key", 1.0) instead of call.getFloat("key") ?? 1.0
- call.getInt("key", 0) instead of call.getInt("key") ?? 0
This fixes Swift compilation errors when building with Capacitor 8
and Swift Package Manager:
error: missing argument for parameter capacitor-community#2 in call
Member
|
Such issues should be catched by CI. Please provide a Minimal, Reproducible Example using this template in a public GitHub repository so I can take a look at it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The v8.0.0 release uses the single-parameter
getString/getFloat/getIntAPI with nil-coalescing:However, when building with Capacitor 8 and Swift Package Manager, this causes compilation errors:
The Capacitor 8 xcframework only exposes the two-parameter variant of these methods.
Solution
Update all parameter extraction calls to use the two-parameter style:
This is the same style used by official Capacitor 8 plugins (e.g.,
@capacitor/status-bar).Changes
speak(): Updated 8 parameter extractionsisLanguageSupported(): Updated 1 parameter extractionTesting
Built and tested against Capacitor 8.0.0 with Swift Package Manager.