Your Android team ships a feature in Kotlin, and the iOS team needs it next sprint. You open an LLM, paste the Kotlin ViewModel, and ask: "Convert this to SwiftUI." What you get back compiles. It even looks like Swift. But somewhere inside, there's a DispatchQueue.main.asyncAfter where you'd expect Task.sleep, a class with a manual deinit fighting ARC, and a @State that resets every time the parent re-renders. The LLM didn't translate the architecture — it translated the syntax and smuggled the old mental model along.
This is the trap: SwiftUI and Jetpack Compose are not translations of each other. They share ideas — declarative UI, state-driven updates — but the memory model, the concurrency primitives, and the lifecycle rules are different enough that a literal port will break in subtle ways. The prompts below are the ones I keep in rotation when moving a feature between Kotlin and Swift, and they're built around that difference, not around syntax conversion.
Why "convert this" is the wrong ask
When you tell an LLM to convert, it optimizes for similarity. That's exactly what you don't want. You want it to respect the platform's idioms, even if the resulting code looks nothing like the source.
Here's what happens in practice. A typical Kotlin ViewModel with a MutableStateFlow and viewModelScope.launch gets converted to a Swift class with an @Published property and a DispatchQueue.main.async block. It works — until the view disappears and the task keeps running, because there's no viewModelScope equivalent and no cancellation. On Android, viewModelScope is cancelled automatically when the ViewModel is cleared. On iOS, you have to manage that yourself with .task modifiers or a stored Task handle. More on the topic: “Swift and iOS Development (SwiftUI): Why "Learning the Syntax in a Couple of Days" Is a Myth and How to Actually Master the Language”.
Where a literal port breaks: Kotlin vs Swift
| Aspect | Kotlin | Swift | Naive port risk |
|---|---|---|---|
| Memory | Garbage collection | ARC (compile-time retain/release) | Retain cycles, leaks |
| Concurrency | Coroutines + Flow | async/await + AsyncSequence | Unstructured tasks, missing cancellation |
| Threading | Dispatchers (Main, IO, Default) | Actors, @MainActor | Blocking main thread with await |
| State | remember / mutableStateOf | @State / @Binding / @Observable | State resets on re-render |
| Lifecycle | viewModelScope auto-cancel | Manual.task or stored Task | Background work outlives view |
The prompt needs to force the model to think about lifetime, not just types.
Prompt 1: The platform-first rewrite
This is the workhorse. It tells the model to throw away the source structure and build from the platform's primitives. Use it when you have a working feature on one platform and need a native equivalent on the other.
Prompt:
You are a senior [iOS/Android] engineer. I will give you a working implementation of a feature from the other platform. Do not translate it line by line. Instead:
1. Describe the feature's observable behavior in 5 bullet points (what the user sees, what state changes, what side effects occur).
2. Implement it natively using [SwiftUI + async/await / Jetpack Compose + coroutines], following the idioms of this platform.
3. List every place where the source platform's memory or concurrency model would have leaked into a literal port, and explain what you did differently.
Source implementation:
[paste code]
Example — Kotlin to SwiftUI:
Source (Kotlin):
class ProfileViewModel(private val repo: UserRepository) : ViewModel() {
private val _user = MutableStateFlow<User?>(null)
val user: StateFlow<User?> = _user.asStateFlow()
init {
viewModelScope.launch {
_user.value = repo.fetchUser()
}
}
}
The model's output (abridged):
Behavior:
- Shows a loading state until user data arrives.
- Displays name and avatar when loaded.
- Fetches once on screen appearance.
- Cancels fetch if the screen disappears.
- No retry on failure (matches source).
Swift implementation:
@Observable
final class ProfileModel {
var user: User?
private var loadTask: Task<Void, Never>?
func load(repo: UserRepository) {
loadTask?.cancel()
loadTask = Task {
user = await repo.fetchUser()
}
}
deinit { loadTask?.cancel() }
}
struct ProfileView: View {
@State private var model = ProfileModel()
let repo: UserRepository
var body: some View {
Group {
if let user = model.user {
Text(user.name)
} else {
ProgressView()
}
}
.task { model.load(repo: repo) }
}
}
Differences from a literal port:
- No DispatchQueue: used structured concurrency with Task.
- Cancellation is explicit via .task modifier, which cancels on disappear.
- Used @Observable (iOS 17+) instead of ObservableObject to avoid manual @Published boilerplate.
Notice the model didn't just rename things. It introduced .task, which ties the fetch to the view's lifetime — the equivalent of viewModelScope but at the view level. That's the kind of insight you want.
Prompt 2: The memory-model sanity check
ARC and GC behave differently, and LLMs often write Swift that assumes garbage collection. This prompt forces a review of ownership.
Prompt:
Review this Swift code for ARC-related issues. For each reference cycle, unnecessary strong reference, or missing weak/unowned, point it out with the line and explain the consequence in a running app. Then rewrite the code to be ARC-safe. Do not suggest changes that would be needed only under a garbage-collected runtime.
Code:
[paste Swift code]
Example: A model review of a coordinator pattern often catches that a closure stored in a view model captures self strongly, creating a cycle. On Android, the same pattern with a lambda wouldn't leak because the GC handles cycles. The prompt makes the model state that difference explicitly.
Prompt 3: Coroutines vs async/await — same feature, two idioms
This is where most cross-platform prompts fail. Kotlin coroutines and Swift concurrency look similar on the surface (suspend vs async, Flow vs AsyncSequence), but the cancellation models and dispatcher semantics differ. Use this prompt when you need to port a data layer.
Prompt:
I have a Kotlin data layer using coroutines and Flow. Produce two outputs:
A) An equivalent Swift implementation using async/await and AsyncSequence.
B) A table comparing the two on: cancellation propagation, error handling, backpressure, and threading/dispatcher model. For each row, note where a naive port would introduce a bug.
Kotlin code:
[paste code]
Example output (table excerpt):
| Aspect | Kotlin coroutines | Swift async/await | Naive port bug |
|---|---|---|---|
| Cancellation | Cooperative, via isActive or ensureActive() |
Cooperative, via Task.isCancelled or checkCancellation() |
Forgetting to check cancellation in loops — task runs to completion |
| Error handling | try/catch around suspend calls |
try/catch around await calls, but Task swallows errors if not awaited |
Unawaited Task hides failures |
| Backpressure | Flow has buffer, conflate |
AsyncSequence has no built-in backpressure; use AsyncStream with buffering policy |
Unbounded buffering causes memory growth |
| Threading | Dispatchers (Main, IO, Default) | No dispatchers; use actors or @MainActor |
Assuming await runs on a background thread |
That last row is the killer. Many developers assume await means "off the main thread." It doesn't. In Swift, you need @MainActor or a detached task to control threading. The LLM will happily write code that blocks the main thread if you don't ask it to check.
Prompt 4: Compose vs SwiftUI state — the recomposition trap
State management is where the two frameworks diverge most in practice. Compose's remember and SwiftUI's @State are not equivalent, and the LLM will often mix them up. This prompt forces a side-by-side comparison. More on the topic: “Coroutines or Compose? How to Aim an LLM at Kotlin So It Doesn't Leak ViewModels, Flows, or Your Patience”.
Prompt:
Explain the difference between Compose's `remember`/`mutableStateOf` and SwiftUI's `@State`/`@Binding` in terms of lifecycle and recomposition. Then take this Compose screen and rewrite it in SwiftUI, adding comments at each state declaration explaining why you chose that property wrapper and what would happen if you used a different one.
Compose screen:
[paste code]
Example: A Compose screen with a remember { mutableStateOf("") } for a text field becomes @State private var text = "" in SwiftUI. But if the Compose code used rememberSaveable, the SwiftUI equivalent is not just @State — you need @SceneStorage or @AppStorage to survive process death. The model will point this out if you ask.
Prompt 5: The "don't write Java in Swift" lint
This is a meta-prompt. Run it on any generated Swift code to catch JVM habits. It's especially useful when the LLM has been primed with a lot of Kotlin context.
Prompt:
Analyze this Swift code for patterns that are idiomatic in Java/Kotlin but wrong in Swift. Look for: manual memory management, getter/setter boilerplate, unnecessary class hierarchies, use of `DispatchQueue` where structured concurrency would do, and explicit null checks where optionals would suffice. For each finding, show the offending line and the Swift-native alternative.
Code:
[paste Swift code]
Example finding:
Line 12: `if user != nil { let name = user!.name }`
Issue: Force-unwrapping after a nil check is a Java habit. Use optional binding.
Fix: `if let user { let name = user.name }`
Line 27: `DispatchQueue.global().async { ... }`
Issue: Unstructured concurrency. Prefer `Task.detached` or an actor.
Fix: `Task.detached { ... }`
Prompt 6: When the LLM should refuse to port
Sometimes the right answer is "don't port this pattern." Use this prompt to get a judgment call.
Prompt:
I need to port this feature from [platform A] to [platform B]. Before writing code, tell me: are there any patterns in the source that have no native equivalent on the target platform, or that would be an anti-pattern there? If so, propose an alternative design that achieves the same user-facing behavior. Only after that, write the code.
Example: A Kotlin feature using LiveData with Transformations.map might not have a clean SwiftUI equivalent. The model should suggest using a computed property on an @Observable class instead of trying to replicate the transformation chain.
Putting it together: a workflow for a real feature
Here's how these prompts chain on a real task — porting a "favorites" feature from Android to iOS.
- Prompt 1 on the ViewModel: get the behavior list and native Swift model.
- Prompt 3 on the repository layer: ensure the data fetch uses structured concurrency correctly.
- Prompt 4 on the screen: map state declarations and catch recomposition differences.
- Prompt 5 on the generated Swift: lint for JVM habits.
- Prompt 2 as a final pass: check ARC safety.
The whole loop takes maybe 20 minutes of back-and-forth, and you end up with code that reads like a Swift developer wrote it — not like a Kotlin developer translated it. More on the topic: “Shadowing, Not Translating: How ChatGPT Prompts Turn Vocabulary Lists Into Actual Speech”.
What this means for your team
If your team is mostly Android developers dabbling in iOS (or vice versa), the biggest risk isn't syntax — it's the invisible assumptions. The LLM will happily carry them over. The prompts above are designed to surface those assumptions and force a decision.
Start with Prompt 1 on your next cross-platform feature. If the model's "differences" list is short or vague, that's a signal to dig deeper — there's probably a memory or concurrency trap it glossed over. And if you're building a library of prompts for your team, keep the ones that ask for comparisons and explanations, not just code. The code is the easy part.
For a broader look at how LLMs handle native mobile codebases, see Swift and Kotlin Prompts That Write Native Code, Not Documentation: A Field Guide for iOS and Android Teams. More on the topic: “12 LLM Prompts for Mobile Release Day: iOS and Android Build Configs, CI Pipelines, and Store Submission Checks”.