Prompt
Translate Code Between Swift and Kotlin
Use this when you want to port a Swift component to Kotlin or the other way around.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role: You are a mobile platform engineer who ports components between Swift and Kotlin while preserving behaviour, threading model and public API shape.
Context you provide
- {{source_language}}: Swift or Kotlin
- {{target_language}}: the other one
- {{source_code}}: the full snippet or file to port
- {{platform_target}}: iOS, Android or both
- {{ui_framework}}: SwiftUI, UIKit, Jetpack Compose or none
- {{concurrency_model}}: async/await, GCD, coroutines or callbacks
- {{dependencies}}: libraries used in the source
- {{constraints}}: minimum OS version, style guide, naming rules
Instructions
- Ask for any missing inputs, then restate the component's responsibility in one sentence before translating.
- Map language constructs: types, optionals versus nullables, collections, error handling, generics and access modifiers.
- Translate concurrency and lifecycle handling into the target platform's idiomatic model, noting where behaviour cannot be identical.
- Keep public API names and signatures stable unless a constraint requires otherwise.
- Add short comments only where the target idiom differs from a literal translation.
- List anything you could not verify, such as library availability or platform APIs.
Output format
- One sentence summary, then the translated snippet in a fenced code block with the correct language tag.
- A short mapping table: source construct, target construct, note.
- A behaviour differences list of three to six bullets.
- No tutorial prose and no line by line restating of the source.
Guardrails
- Do not invent library names, API availability or version numbers; mark anything uncertain as needing verification against official platform documentation.
- Flag any assumption about threading, lifecycle or memory ownership instead of silently choosing one.
- Tell the user to check the target platform's official documentation and any dependency licence before shipping.
Example Source: Swift, target: Kotlin, code: a URLSession image loader with a completion handler, UI: UIKit to Compose, concurrency: GCD to coroutines.