GitHub Copilot for Xcode
In the first lesson you discovered that LLMs can be quite useful for iOS development, but there were some limitations around the chat-interface that made coding with them hard work.
In this lesson you’ll learn about GitHub Copilot for Xcode, a companion app which
Context
One of the reasons that the chat interfaces are limited is due to their lack of context. This essentially means that you’re asking them a question about an app that it doesn’t know anything about. It will have a go at answering you, but it does so in a vacuum.
The seemingly crude way you provide context to an LLM (at its simplest level) is to send relevant information (directory structure, metadata, code) at the start of the request. You could absolutely do this yourself using a chat interface—pasting in the code from a file, and then asking ChatGPT something about it, or to continue development on something related. This would very quickly become incredibly frustrating.
All of the coding tools in this module, including GitHub Copilot for Xcode simplify this, by building prompts that include the relevant project-specific context. That might mean sending entire files of code, or directory structures as part of the prompt to the LLM. Essentially, a lot of the features present are nice, convenient wrappers around an LLM prompting engine.
This is an over-simplified view—there are many advanced techniques around this, like using multiple models, splitting input etc—but these are just tweaks on the fundamental approach.
GitHub Copilot
GitHub (i.e. Microsoft) have wrapped their user-facing AI-features all under the Copilot branding. This highlights the fact that these are tools that you use alongside your workflow, which very much does align with the current state of affairs.
GitHub Copilot takes many forms—from enhanced code completion in Visual Studio code, to a robot that will take an issue, and generate a pull-request that addresses it. New functionality is being added all the time, in quite an exciting manner.
The majority of the Copilot coding tools are baking into Visual Studio Code, which is fantastic for many platforms. However, Apple platforms such as iOS rely fairly heavily on Xcode.
Xcode has some rudimentary extension points, but not enough to allow Github to fully integrate the features from Copilot. Therefore they have released a companion app called GitHub Copilot for Xcode, which brings the features of Copilot into Xcode, albeit in a slightly clunky manner.
Modes of Operation
Copilot in Xcode has four principal features:
- Code completion We’ve been used to automatic code completion in IDEs for many years. In fact, Microsoft even gave theirs a marketing name in the shape of Intellisense. However, adding AI to code completion allows it to take the context of the code around it, and infer from that the code that you want to write. That can manifest itself in the form of recognising repetition, guessing how you are likely to use common APIs, through to attempting to write entire function definitions from a comment or a function name. The companion app is used here to soup up the code completion in Xcode, and you’ll just notice that it has suddenly become significantly more powerful.
- Ask The primary way that you’ll interact with AI whilst coding is via chat, very similar to how you were introduced to LLMs with ChatGPT. Ask mode is essentially ChatGPT, but with added context. The LLM has access to the files in your project to include in its understanding. Although it can generate code, it can’t really do anything with it.
- Agent This is like a souped up version of Ask, in which the AI is empowered to make changes to files directly. So rather than just generating code and leaving you to apply it, Agent mode can make the edits directly to any files in the project.
- MCP support Agent mode can create and edit files, but imagine if it could do more! That’s what Model Context Protocol (MCP) allows. It’s a standardised protocol that allows agents to access additional tools. For example it could have a tool that describes how to run a test suite on your code, which would allow the agent to run your tests for you.
This lesson is an introduction to using GitHub Copilot for Xcode, so we won’t have a chance to cover MCP support, but we’ll delve into the other three major features.
Cost
GitHub Copilot for Xcode requires you to login with your GitHub account. Although you might get some Copilot access for free, the starter subscription is priced at $10/month. You might have to sign up to be able to follow along with this lesson.
Alternatively, GitHub provides free access to Copilot for people that contribute to open source, so you might be able to subscribe that way.