OpenAI had announced ChatGPT integration for Xcode previously. They have now released this capability for all users, including the free tier. Previously using ChatGPT with a paid account, I have recently stopped using it this way, since I’ve been experimenting with an application using the ChatGPT API, which is much cheaper than using a $20 monthly account.
When I got the announcement from OpenAI, I immediately tried to use this capability. The way to activate it is to start Xcode and open the file you are interested in analysing or editing. Then you activate ChatGPT by pressing Option-Space Bar. The first time you do this, the familiar chat window opens, with a document reference being used to install ChatGPT support. Clicking this results in launching System Settings with the intent to let ChatGPT to control your computer (Now this looks suspiciously similar to what they did in Terminator before everything went haywire, but well… I guess we are not there yet).
Once the setup is complete, the ChatGPT chat window shows the name of the active source file as a document reference.
Now you can interact with ChatGPT. It has the context for what is on screen and can apply your request to it. To start easy, I asked it to comment on the Swift code.
First it provided some general comments on the code and then started going into deeper analysis.
So far, so good. Then I started looking into the detailed comments and suggestions. Note that it gives me the chance to copy each suggested code change and paste it manually to Xcode as required. At the end of the chat it also asked me whether it should implement any of its suggestions directly on code. I was too afraid to let it do this, since I was working on my actual code and not on a sample.
The first item is more of a warning. This is indeed a concern, since this view would retrieve everything given it has no filtering predicate.
The second item is basically a minor point. In this particular view I do not want any animation, thus using the constant makes sense. However it could have been designed differently, which I will admit.
Here things start to get a bit messy. The comment is not appropriate, since pulsate is defined as a state variable in the beginning of the file and is initialised.Although it is not really changed within the view, this would be possible later with some changes in the user interface, so in a sense this comment contradicts with the previous one.
Now, this one is debatable. It is true that in theory the creation of a SavedChat object (newChat) could fail (albeit very unlikely). The second comment is a bit strange. It refers to the possibility of a delay in saving, however the newly created object is added to the collection immediately even if the saving may be done later (especially if the SwiftData property for autoSave is set to false). Since the check is done on the container (an array, basically), it would always work.
ChatGPT has not understood what this - very typical - Swift code is trying to do. It is trying to delete only the lines that have been marked for deletion using the swipe action (typical action for iOS or MacOS users) and not to delete all lines. ChatGPT basically provides code that would delete all lines. It removes all references to offset, again a standard way to get all lines in a List that have received the swipe action. Warning bells…
I then tries to use it for some stylistic support. I am not the best designer around, so I always need help to come up with visual elements that are more appealing. So my next request reflected this.
This resulted in some suggestions which were clearly generic but applied to the code at hand. So, this could be quite useful to try out.
The suggestion is debatable, especially if there is little screen real estate available, but is a legitimate one.
This is really generic, but in this particular case it might work, given that the icon used is a question mark and can be in a rounded button for sure.
This is indeed a good suggestion, but eventually one has to check the aesthetic appeal of the final result.
This is indeed a good suggestion and can be used on MacOS.
These are also interesting suggestions to try out. I’ve also noted that it provides explanations for the reasons for each snippet it suggests.
I am more hopeful about stylistic suggestions, but I suspect ChatGPT might be missing the context in large codebases. However, this is my first foray into coding with an LLM and I will certainly experiment with it further and will report it later.












