DEV Community

 Aiden Shaw
Aiden Shaw

Posted on

This Is How I Use AI to Write, Refactor & Test Swift Code (No BS, Just Workflow)

Let me guess:You’ve tried asking ChatGPT to “write a SwiftUI view with a login screen”……got a decent result.But then it broke when you added Combine or changed one binding.

Yeah — I’ve been there.

But over the last year, I’ve started using AI tools in a much deeper, more integrated way — not just copy-pasting code into a browser, but wiring up actual AI workflows inside VS Code, Terminal, and even Xcode.

So here’s how I actually use AI every day as an iOS dev to write Swift, refactor legacy code, and even generate test coverage for my modules — no BS, just real-world examples.

If you're building something bigger — like a production-grade mobile app — and want to speed this up with help from a pro team, check out Shakuro’s iOS development services. Their full-cycle dev flow is about as optimized as it gets.

Let’s jump in 👇

🧠 Step 1: AI-Assisted Swift Writing Inside VS Code

✅ Tool: Codeium

Forget copy-pasting from ChatGPT. Codeium brings AI suggestions directly into your editor (VS Code, Xcode, JetBrains – you pick). It works like Copilot, but it’s 100% free and plays well with Swift.

How I use it:

  • Scaffolding SwiftUI views (NavigationStack boilerplate, etc.)

  • Auto-completing async/await logic or Combine pipelines

  • Filling in edge-case logic in reducers or view models

I even trained it on my project’s naming conventions. It picks up patterns across files, which is 🔥 for maintaining consistency.

Pro Tip: Pair Codeium with the Swift for VS Code extension and SourceKit-LSP for the full Swift coding experience in VS Code.

🔁 Step 2: Refactor Legacy Code With an AI Agent

✅ Tool: ForgeCode or Cline

These agents live in your terminal or editor — and they’re aware of your whole codebase. That means they can actually refactor real projects, not just isolated functions.

Use case:

`> Explain how the networking layer is structured

Rewrite it using async/await
Split this monolithic view into smaller SwiftUI components`

The AI looks through multiple files, suggests clean refactors, and even offers reasoning ("This makes it testable," "Avoids retain cycles").

I recently used ForgeCode to:

  • Replace URLSession-based networking with async let calls

  • Move core logic to shared modules in a modularized SwiftPM project

  • Flatten complex view hierarchies into clean MVVM components

No hallucinated nonsense — just contextual, repo-aware AI editing.

✅ Step 3: Auto-Generate Tests (Yes, Useful Ones)

✅ Tools: Kilo Code + XCTestDoc

Writing tests is always the “we’ll do that later” thing. But AI changed that for me.

Here’s how I do it:

  1. Highlight a Swift class or function

  2. Ask Kilo Code: “Generate XCTest cases for this module”

  3. Boom — it creates snapshot tests, edge-case scenarios, even mocks using @testable import

Then I run everything via:

swift test

And with XCTestDoc, I get clean, auto-generated test documentation that I share with PMs or designers during QA rounds.

⚠️ Note: You still have to read the generated tests — AI helps, but doesn’t replace critical thinking.

🛠 Bonus: Fastlane + AI for CI/CD

Tool: Fastlane

You can script Fastlane workflows and then have AI optimize them.

Prompt:

“Create a Fastlane config to build, sign, and deploy my app to TestFlight, using automatic provisioning and screenshots”

Kilo Code or ForgeCode can:

  • Create the Fastfile

  • Add match or cert configs

  • Set up automatic screenshot generation for App Store upload via snapshot

Perfect for teams, solo devs, or freelancers running multiple projects.

🔄 Xcode vs VS Code: My Hybrid AI Workflow

I write in VS Code, run tests via CLI, preview in Xcode. Best of both worlds.

Final Thoughts

AI isn’t just a hype train — it’s quietly transforming how I build iOS apps.

I still write code manually. But now I spend less time on boilerplate, more time on architecture, and almost no time staring at broken tests.

You don’t need a fancy setup. Just install a few extensions, wire up an agent, and start talking to your codebase like a human.

And if you’re building something bigger — an MVP, SaaS app, mobile platform — and want to move fast with quality, check out Shakuro’s iOS app dev team. They do full-cycle builds and can plug into your AI-enhanced workflow too.

💬 How are you using AI in your Swift projects?🧪 Got any agents or plugins I missed?

Drop a comment or ping me — always down to swap workflows.

Top comments (0)