Skip to content

Comments

fix: Use two-parameter API for Capacitor 8 Swift compatibility#158

Open
sgalloway wants to merge 1 commit intocapacitor-community:masterfrom
sgalloway:fix/capacitor-8-swift-api
Open

fix: Use two-parameter API for Capacitor 8 Swift compatibility#158
sgalloway wants to merge 1 commit intocapacitor-community:masterfrom
sgalloway:fix/capacitor-8-swift-api

Conversation

@sgalloway
Copy link

Problem

The v8.0.0 release uses the single-parameter getString/getFloat/getInt API with nil-coalescing:

let text = call.getString("text") ?? ""

However, when building with Capacitor 8 and Swift Package Manager, this causes compilation errors:

error: missing argument for parameter #2 in call
    let text = call.getString("text") ?? ""
                                    ^

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:

let text = call.getString("text", "")

This is the same style used by official Capacitor 8 plugins (e.g., @capacitor/status-bar).

Changes

  • speak(): Updated 8 parameter extractions
  • isLanguageSupported(): Updated 1 parameter extraction

Testing

Built and tested against Capacitor 8.0.0 with Swift Package Manager.

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
@robingenz
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants