ChatGPT in Xcode: is it good?


You’re more of a video kind of person? I’ve got you covered! Here’s a video with the same content than this article 🍿


Advertisement

Debug HTTP/HTTPS with Proxyman like a Pro

Try Proxyman, a native macOS app that captures and displays Request/Response in beautiful UIs.

Supports iOS and Android, both devices and simulators.

Get 30% off discount for Black Friday with the code BLACKFRIDAY2024

👉 Get it before it's too late! 👈


Sponsors like Proxyman really help me grow my content creation, so if you have time please make sure to check out their survey: it’s a direct support to my content creation ☺️


In this article, I want to show you how it’s now possible to quite seamlessly use ChatGPT directly from within Xcode!

It’s been 2 years since ChatGPT has been released, and during that time it managed to become a very popular tool for software engineers!

But if you’ve tried to integrate it to your workflow, you’ve probably noticed how tedious it can be to keep copy pasting between ChatGPT and Xcode.

Things are changing however: the native macOS app for ChatGPT is now able to (partially) integrate with Xcode.

I gave it a try last week during a livestream, and now I want to share with you my feedback!

Let’s start with how it works.

First, you’ll need to download the macOS app and enable it to work with Xcode.

(as of when I’m writing this article, working with Xcode also requires to purchase a ChatGPT Plus subscription)

And then, in Xcode you’re now able to use the shortcut Option ⌥ + Space: it will open a ChatGPT window, with the content of the current file automatically attached to your prompt:

Even better, if you make a selection in the current file, ChatGPT will also be aware of which lines you’ve selected, so that it can focus its answer on that part of the code:

When you put it all together, it enables a pretty seamless workflow:

  1. select the code that you want to update

  2. use Option ⌥ + Space to open ChatGPT

  3. write your prompt

  4. copy the result

  5. close the ChatGPT window

  6. paste the result back into Xcode

Here’s an example of this workflow, where I ask ChatGPT to refactor a function to make it use async / await instead of a completionHandler:

However, be careful!

Because this workflow is so seamless, it also makes it incredibly easy to overlook the code generated by ChatGPT and to end up adding subtle bugs to your codebase!

This actually happened to me twice during my livestream 🥲

You’ll also want to keep in mind that ChatGPT isn’t up-to-date with the latest iOS APIs.

For instance, it doesn’t know how to use Swift Testing or even the new SwiftUI Observability API that’s been released over a year ago…


So what’s my take on this new integration of ChatGPT with Xcode?

Overall, I’ve been pretty pleased with the experience: it really lowers the effort of making ChatGPT work with your iOS code.

If you’re already used to asking ChatGPT for help, you’ll definitely enjoy it.

And if you’ve never really given it a try, it’s also a great opportunity to experiment with it without having to make too much of an effort!

(But be careful to always check the code that it generates!)

Previous
Previous

let is a lie (sometimes)

Next
Next

New in Swift 6: a macro to make debugging easier