If you were doing development on pretty much anything other than iOS or Apple based platforms, you would probably be using a tool like Visual Studio Code or potentially IntelliJ, JetBrains, JetBrains, IntelliJ, J or some other, essentially a text editor that’s been souped up into an IDE, or maybe even just a text editor. An example of that is a tool called cursor.
Cursor is based on Visual Studio Code, but enhanced with real, with in-built AI technologies. You can get it at cursor.com funky looking website, and it runs through some of the things it can do. So we’ve got it does predicting your next edit. So tab tab tab is essentially code completion but really clever. Similar in fact to what we saw in GitHub co-pilot for Xcode.
It knows your entire code base. So this is something that co-pilot wasn’t quite so good at, is that this is better at being able to use bigger context. You can do inline edits using natural language, and there’s a whole host of other things as well, including agenetic mode, the same as we saw before.
Now you need to create an account cursor.com to be able to use it. It is available for free. The stuff we’re going to do today just uses a free account. But you can upgrade for $20 a month, which includes more requests. Essentially all of these AI products are based on how many requests you use or how many tokens that you use.
Some models are based on a subscription where you get a certain amount and then you can overpay so you pay if you go over, others based on actual pay-per-play. So when we look at Claude later on in the next lesson, then you’ll see that actually I’m using the API, which allows you to pay per per token.
So we’re going to go with the free one, download it. It’s same very easy install as before. And then I’m going to open it up here. So this is what it looks like when you open it. No I’ve already signed in as well. And I encourage you to sign in. And if you need to sign in to use any of the AI features, so that it knows who you are and how much of the free plan that you’ve used.
So I’m going to go ahead and open a project very quickly. You don’t open the Xcode project, you do in Xcode. I’m just opening the directory that contains it. And you’ll see it looks the same as it does elsewhere.
Now it’s a slightly different workflow. You can because it’s Visual Studio Code you can add plugins and things so that you can work with Xcode, so that you can work with building Swift apps directly inside cursor. The easiest way to do it, though, is to use cursor to do your edits, and then switch over to Xcode to compile it and see how it’s doing. It might feel a little bit clunky at first, but as a general rule, it does get, it does get easier.
So let us have a look. So it’s exactly the same directory structure that we’ve seen before. So you’ve got the spec the interface is fairly familiar on the most part. We have a chat down the side. You can choose the type of mode that you want. So you can go an agent or ask. There’s a whole selection of models that you can use. You can’t use many of these unless you, unless you pay.
So there are things like GPT 4o GPT 4.1, the same that we were using elsewhere. Cursor small cursor is an interesting one, because that is its own custom model that it uses for things like code completion and often with using AI is the combination of different models that makes quite a big difference.
So when you’re using free, then the best way of doing is to use auto. I would if you if you paid, then I think Gemini is really powerful. But first we’re just going to choose auto. It’s going to choose its model for us.
Okay. So what are we going to do with this? Well let’s start with what we’ve been doing before and let’s get it to take a look at the spec and to tell us how much of it we’ve implemented, and to give us a plan for how we want to do it.
I’m going to leave it in agent mode, and I’m going to ask it, please could you read the spec and tell us tell me what we need to do to finish implementing it?
The thing that is notably different from Co-Pilot for Xcode is that it can do other things and just use the context of the current file. So for example, it can look in the current directory. Then it will go off and look in the main app directory. It reads them all. It reads the weather view model and then it runs down.
And from there it’s worked out. Where we need a location services. We need a time service module. We haven’t got the weather API yet. We haven’t got the weather assets class to map the weather codes to symbols. We haven’t done a geocoding service. There’s loads. I need to update the weather view. We need to update the weather ViewModel. We need to add some unit tests, and it’s then so it’s written out a plan and then asked, well, what should we do?
And what I would like to do is concentrate on the weather API client. So I’d like it to create the client. Don’t know how well this is going to go each time you use because it’s non-deterministic. Each time you use a, you get a different result. So I’ve now recorded this video four times. Each time is completely different. So let’s see what happens.
I would like you to create the weather API client please. Okay. Let’s see what it does. It’s decided it needs to use make requests to this archive thing because we originally said Open Meteo. And then it tells you the file that it’s going to create and gives you the code.
And then it tells you it’s created it and it’s created some models of weather response, hourly data and weather error and tells you a little bit about what it’s done or gives the required parameters. Now, I would highly suggest and like, as with everything that I generates your code reviewing it. I would go and have a look at the API and make sure that what it’s done matches what you expect the API to do.
We’re going to live a little dangerously here and just ignore it, but let’s go ahead and and even shows you how the client is designed to be used, which is quite helpful as well. So now it’s asking, do you want some unit tests? Should we create the weather asset? So update the weather ViewModel.
Well, let’s first of all how do we review this code. It’s written. You’ll notice this button that appears in the bottom centre code review. Next file. So I’m going to jump to that. We’ve only got one file to review at the moment. As we do bigger edits you’ll see more and more files in there.
But this is what the model looks like. It’s got a code about hourly data thing which takes the time, temperature and weather code and precipitation. So those are things that will come back from the API. And it’s added the coding keys so that it can decode what arrives from the API into our struct.
It decided that it’s got some errors. So we’ve got invalid URL network, invalid response decoding error, and no type data for time and the errors that it’s decided it needs. And then from there it’s created the client itself. So we’ve got a fetch weather async throws which is going to take a latitude longitude and a date. It’s going to return the temperature. The weather code and precipitation.
Which so it’s going to format that, figure out what the date needs to be. It’s using, you using the date that we’ve passed in and then formats the URL using URL components. We check that the URL is valid and then it will go off and use as a shared URLSession and grabs the data.
We’ve got an invalid response unless it’s in the 200 range. And then tries to decode it, which is where we might get a decoding error, in which case I’ll throw a weather error decoding error. And otherwise it’ll catch a network error as well. So it’s got some pretty good error handling built in from the start.
I’m reasonably happy with that. And then we’ve got it then pulls out the hours. So this is we need to know about the API to be able to understand this. I’m just going to let it go for now so I can either this if you had multiple edits, you can accept or reject each one one by one. Well, here I can accept the whole file. So I’m going to do that.