Skip to content

Adding support for iOS using KMP#13

Open
zurche wants to merge 1 commit intomainfrom
kmp-initial-updates
Open

Adding support for iOS using KMP#13
zurche wants to merge 1 commit intomainfrom
kmp-initial-updates

Conversation

@zurche
Copy link
Owner

@zurche zurche commented Dec 22, 2025

KMP: shared core + Compose UI, iOS app bootstrap, and persistence updates

Summary

This PR migrates the calculator core and UI to a shared KMP module, adds an iOS app wrapper using Compose Multiplatform, and updates Android wiring to consume the shared store. It also replaces the JVM-only engine with a KMP-safe parser, restores Android fonts via androidMain, and documents the iOS setup.

Key changes

  • Shared KMP module with engine, models, state/store, and Compose UI.
  • Android ViewModel now delegates to shared CalculatorStore.
  • iOS app scaffolding (SwiftUI host + CocoaPods integration).
  • iOS persistence via NSUserDefaults repository.
  • Fonts restored on Android via expect/actual typography.

Architecture (after)

graph TD
  subgraph Shared[KMP shared]
    UI[Compose UI]
    Store[CalculatorStore]
    Engine[CalculatorEngine]
    Repo[HistoryRepository]
  end

  subgraph Android[Android app]
    VM[CalculatorViewModel]
    DS[DataStoreHistoryRepository]
  end

  subgraph iOS[iOS app]
    Swift[SwiftUI Host]
    IOSRepo[IosHistoryRepository]
  end

  Swift --> UI
  VM --> Store
  Store --> Engine
  Store --> Repo
  DS --> Repo
  IOSRepo --> Repo

Loading

Data Flow

sequenceDiagram
    participant UI as Compose UI (shared)
    participant Store as CalculatorStore (shared)
    participant Engine as CalculatorEngine (shared)
    participant History as HistoryRepository (platform)

    UI->>Store: onAction(CalculatorAction)
    Store->>Engine: evaluate(...) / toggleLastOperandSign(...)
    Engine-->>Store: EvaluationResult / updated expression
    Store->>History: addHistory(...)
    Store-->>UI: uiState (StateFlow)
    Store-->>UI: invalidExpressionEvents (SharedFlow)

Loading

iOS setup notes

  • ./gradlew :shared:podspec :shared:generateDummyFramework
  • cd iosApp && pod install
  • Open iosApp.xcworkspace
  • If Xcode reports a sandbox error for CocoaPods scripts, disable User Script Sandboxing for both iosApp and Pods-iosApp targets.

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.

1 participant